Double backslash in front of local URL - php

Is there a way to navigate to a file on a local location which uses a double backslash at the start like this: \192.168.1.1\folder\file.xml ?
I have tried several ways like this:
file_get_contents("\\192.168.1.1\folder\file.xml");
fopen("\\192.168.1.1\folder\file.xml", '');
But it keeps failing to open the file. while navigating to it locally seems to work.

you need a backslash to escape every backslash (a backslash is the escape char in coding)
So you would have:
$addr = "\\\\192.168.1.1\\folder\\file.xml";

#Craig B - Beat me to the answer by few seconds, you should use double double
"\\\\192.168.1.1\\folder\\file.xml"

Related

PHP glob can't read tmp

I am using wamp in win7, and I try to read c:\wamp\tmp by glob with php, but the result is an empty array
print_r(glob("C:\wamp\tmp\*"));
I can see any folder in c:\wamp except c:\wamp\tmp, and I make sure that folders has the same setting about read write...
\t is an escape sequence that means the Tab character. You have several ways to deal with it:
Escape it with another backslash.
print_r(glob("C:\wamp\\tmp\*"));
Use single quotes instead of double quotes, since escape sequences aren't processed in single quotes.
print_r(glob('C:\wamp\tmp\*'));
Use forward slashes instead of backslashes, since Windows allows either as a directory separator.
print_r(glob("C:/wamp/tmp/*"));

Esthetic How To Reverse Quotes

Okay I am almost done with my project finally and im not sure how secure it really is but its a jumping off point and will see if the site ever gets any traffic if so many ill pay to have someone fix some things other wise it can wait while I keep learning but long story short I have it outputing a file
And I am having a bit of trouble with it.
here is my code
file_put_contents('DONE.html', '<html><?php include('config.php'); </html>');
But as im sure you can see my issue is that since this whole string is put into ' quotes it dosnt read the config.php correctly because it thinks it should be out of quotes how do I fix this cause I have a ton of ' And " that need to be added to this and im not sure how to make my php script out put quotes.
Quote characters in strings delimited by the same character should be escaped with a reverse solidus / backslash character.
file_put_contents('DONE.html', '<html><?php include(\'config.php\'); </html>');
There are a few ways to achieve what you want to do:
file_put_contents('DONE.html', "<html><?php include('config.php'); </html>");
file_put_contents('DONE.html', '<html><?php include("config.php"); </html>');
file_put_contents('DONE.html', "<html><?php include(\"config.php\"); </html>");
You basically alternate between single and double quotes, or escape (with backslash ) the double quotes within double quotes so it doesn't close the previous one.
Anyway I think what you want to do is kind of strange. Instead of adding the include into that file, why don't you just include the config.php directly? what happens if you change the config.php's name or path? You would have to change it from all the files, why don't just:
<?php
include("config.php");
include("DONE.html");
?>

How to escape special character ' \ '?

I use php to retrive the data from table and ajax to display the result.
When I search using location for the 1st time, I get the result and the pagination is not working, especially for "istanbul".
The reason is the special character '\' added with the address that's taken from Google map.
The URL passed when i go to next page, is
http://www.mysite.com/dropinn/search/\"http://www.mysite.com/dropinn/search?checkin=mm%2Fdd%2Fyy&checkout=mm%2Fdd%2Fyy&guests=1&location=Istanbul%2C+Turkey&min_bathrooms=0&min_bedrooms=0&min_beds=0&per_page=10&search_view=1&sort=1&page=3"
How to over come this problem?
This is the code that I have written:
$config['base_url'] = site_url('search').'?checkin='.urlencode($checkin).'&checkout='.urlencode($checkout).'&guests='.$nof_guest.'&location='.urlencode($location).'&min_bathrooms='.$min_bathrooms.'&min_bedrooms='.$min_bedrooms.'&min_beds='.$min_beds.'&per_page='.$per_page.'&search_view=1&sort='.$sort;
Using double quotes, you escape \ with another \. If you need to display a \, then you must type \\, or you could use single quotes.
Example: echo "\hello\world"; would need to be echo "\\hello\\world";, or echo '\hello\world';
To escape in php, you must use \\
Try this:
http://www.mysite.com/dropinn/search/\"http://www.mysite.com/dropinn/search?checkin=mm%2Fdd%2Fyy&checkout=mm%2Fdd%2Fyy&guests=1&location=Istanbul%2C+Turkey&min_bathrooms=0&min_bedrooms=0&min_beds=0&per_page=10&search_view=1&sort=1&page=3\"
Or this:
http://www.mysite.com/dropinn/search/\\"http://www.mysite.com/dropinn/search?checkin=mm%2Fdd%2Fyy&checkout=mm%2Fdd%2Fyy&guests=1&location=Istanbul%2C+Turkey&min_bathrooms=0&min_bedrooms=0&min_beds=0&per_page=10&search_view=1&sort=1&page=3\"
Or lastly:
http://www.mysite.com/dropinn/search/\\"http://www.mysite.com/dropinn/search?checkin=mm%2Fdd%2Fyy&checkout=mm%2Fdd%2Fyy&guests=1&location=Istanbul%2C+Turkey&min_bathrooms=0&min_bedrooms=0&min_beds=0&per_page=10&search_view=1&sort=1&page=3\\"
Your question is a little confusing without seeing more code, but those should work.

Accessing a defined constant returns messed up characters

This is strange I have a constant defined as such:
define("RJ_FILES_PATH", RJ_SITE_DIRECTORY."\assets\files\\");
However when I try to access the constant in code I get this weird result on my localhost..
C:\wamp\www\my.app\assetsiles\2688
The \f is replaced by a square indicating it as an unrecognised character. Whats happening because of this I am unable to save files to the folder the constant is supposed to point to.
You need to escape the backslashes before the a and the f:
define("RJ_FILES_PATH", RJ_SITE_DIRECTORY."\\assets\\files\\");
Otherwise they're interpreted as escape codes, since they're within a string. (Just like \n is a newline, et cetera.)
You could—and probably should—just use forward slashes (/) in your file/directory paths. PHP will automatically convert them to the value of the built-in system-dependent constant DIRECTORY_SEPARATOR when using the string as a file path. This is by far the most cross-platform method of doing it.
Alternatively, you could use single quotes. They interpolate backslashes (\) differently in that most escapes are ignored and just interpreted literally (the exceptions being \\ and \').
# *
define('RJ_FILES_PATH', RJ_SITE_DIRECTORY.'\assets\files\\');
# * still need an escape here because of \'
You should escape the backlash by double it: \
In my opinion, you always should use '/', because it work fine in windows and linux. In php, there's a constant DIRECTORY_SEPARATOR but it's uneccesary because '/' work fine.

PHP replace double backslashes "\\" to a single backslash "\"

Okay so im working on this php image upload system but for some reason internet explorer turns my basepath into the same path, but with double backslashes instead of one; ie:
C:\\Documents and Settings\\kasper\\Bureaublad\\24.jpg
This needs to become C:\Documents and Settings\kasper\Bureaublad\24.jpg.
Note that you may be running into PHP's Magic Quotes "feature" where incoming backslashes are turned to \\.
See
http://us2.php.net/magic_quotes
Use the stripslashes function.
That should make them all single slashes.
Have you considered the stripslashes() function?
http://www.php.net/stripslashes

Categories