murdocsvan Posted June 26, 2010 Share Posted June 26, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/205954-php-doesnt-like-in-string/ Share on other sites More sharing options...
kenrbnsn Posted June 26, 2010 Share Posted June 26, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/205954-php-doesnt-like-in-string/#findComment-1077706 Share on other sites More sharing options...
premiso Posted June 26, 2010 Share Posted June 26, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/205954-php-doesnt-like-in-string/#findComment-1077712 Share on other sites More sharing options...
murdocsvan Posted June 27, 2010 Author Share Posted June 27, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/205954-php-doesnt-like-in-string/#findComment-1077731 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.