davidthygreat Posted July 9, 2011 Share Posted July 9, 2011 I have this code within this exercise im doing trying to teach myself php, i don't understand why there are slashes used in this echo statement could someone please tell me why you would need to use slashes in this statement this is reall confusing. echo "<input type=\"hidden\" name=\"travel[]\" value=\"$t\" />\n"; thanks Link to comment https://forums.phpfreaks.com/topic/241489-what-does-this-mean/ Share on other sites More sharing options...
gizmola Posted July 9, 2011 Share Posted July 9, 2011 There are a few different ways to make strings in php. I'm not going to write a book on it right now, but the main ones are: $string = "Hello there"; $string2 = 'Hello there too'; So you can see that either single or double quotes delimits the start and end of the string. So the obvious question becomes... how would i have a string like: Hello there "friend" With single quotes it would not be a problem. $string = 'Hello there "friend"'; But if you tried to use double quotes, the parser would not know where you meant the string to end, and would generate a parsing error. $string = "Hello there "friend""; // doesn't work So when you want to embed characters in a string, you can use the escape character which in php is the backslash(\) to tell php that the character you're escaping (the following character) is a special character that should be treated as part of the string. $string = "Hello there \"friend\""; As you can see there are other escape characters like the "\n" which have special meaning in an interpolated php string (one created using enclosing "...") Link to comment https://forums.phpfreaks.com/topic/241489-what-does-this-mean/#findComment-1240488 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.