Jump to content

Recommended Posts

Here is my code:

 

$site_image = "D:\Hosting\html\" . $_POST['image'];

 

I get the following error:

 

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING

 

The problem:

 

For some reason, PHP doesn't likle me putting "\" at the end of the string, but doesn't mind if it's in the middle. Is there a way around this?

Link to comment
https://forums.phpfreaks.com/topic/205954-php-doesnt-like-in-string/
Share on other sites

The "\" character is the escape character. To use one "\" in a string you need two "\\".

 

Use a forward slash in the file spec. PHP know enough to translate to the Windows form when you're running on Windows. This way you don't have to change your code when you move it to a Linux server.

 

Ken

You could also probably (not knowing how your server is setup) get away with using:

 

$_SERVER['DOCUMENT_ROOT'] to get to your server document root instead of having to manually define it. This will also make the code a bit more portable.

 

Thanks for that, very helpful :)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.