bobleny Posted May 1, 2007 Share Posted May 1, 2007 Say for example I am echoing text: echo "Some text"; Now, what If I wanted to echo some text like this: echo "Hello there, I'm Bob. I'm here to tell you of a quote I've once herd, "Behind every little problem there's a larger problem, waiting for the little problem to get out of the way." Straight from Murphy's mouth!"; How would right that? I can't use '' around the echo, and I can't use "" on it either.... I was under the impression that you would use a slash (/) before it. Maybe the slash only works with the MySQL database.... Quote Link to comment https://forums.phpfreaks.com/topic/49445-solved-just-a-simply-question-about-quotes-inside-of-quotes/ Share on other sites More sharing options...
trq Posted May 1, 2007 Share Posted May 1, 2007 Use \ to escape the double quotes. echo "Hello there, I'm Bob. I'm here to tell you of a quote I've once herd, \"Behind every little problem there's a larger problem, waiting for the little problem to get out of the way.\" Straight from Murphy's mouth!"; Quote Link to comment https://forums.phpfreaks.com/topic/49445-solved-just-a-simply-question-about-quotes-inside-of-quotes/#findComment-242322 Share on other sites More sharing options...
DaveEverFade Posted May 1, 2007 Share Posted May 1, 2007 Before the " or ' you need a \ so it would be echo "some words \"Quote\" more text "; etc... Quote Link to comment https://forums.phpfreaks.com/topic/49445-solved-just-a-simply-question-about-quotes-inside-of-quotes/#findComment-242323 Share on other sites More sharing options...
Ninjakreborn Posted May 1, 2007 Share Posted May 1, 2007 There are 2 options here. One use single quotes echo 'Hello, dave said "What are you doing today", and that was it'; or echo "Hello, dave said \"What are you doing today\", and that was it"; If you aren't doing extrapolation or aren't planning on it, then you want to stick with single quote's to keep it cleaner, if there are some extrapolations then you have to use double quotes, or you can't do that with variables, unless you concatenate them in like echo 'hello what is ' . $user . ' doing today.'; Quote Link to comment https://forums.phpfreaks.com/topic/49445-solved-just-a-simply-question-about-quotes-inside-of-quotes/#findComment-242324 Share on other sites More sharing options...
jitesh Posted May 1, 2007 Share Posted May 1, 2007 <?php echo stripcslashes("Hello there, I'm Bob. I\'m here to tell you of a quote I\'ve once herd, \"Behind every little problem there\'s a larger problem, waiting for the little problem to get out of the way.\" Straight from Murphy\'s mouth!"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/49445-solved-just-a-simply-question-about-quotes-inside-of-quotes/#findComment-242326 Share on other sites More sharing options...
bobleny Posted May 1, 2007 Author Share Posted May 1, 2007 OK, so this: echo "Hello there, I'm Bob. I'm here to tell you of a quote I've once herd, "Behind every little problem there's a larger problem, waiting for the little problem to get out of the way." Straight from Murphy's mouth!"; would need to be this: echo "Hello there, I\'m Bob. I\'m here to tell you of a quote I\'ve once herd, \"Behind every little problem there\'s a larger problem, waiting for the little problem to get out of the way.\" Straight from Murphy\'s mouth!"; What happens to the all of the slashes (\) after it is echoed? are they still there or do I need to use stripcslashes() like jitesh recommended. The only reason I ask is because I am unable to try it here on this computer... :'( Quote Link to comment https://forums.phpfreaks.com/topic/49445-solved-just-a-simply-question-about-quotes-inside-of-quotes/#findComment-242341 Share on other sites More sharing options...
Ninjakreborn Posted May 1, 2007 Share Posted May 1, 2007 No those aren't related to database commands, they are strictly related for php. Those are totally ignored. The idea is PHP need's those to be able to tell it's still part of it. Here there's something better than us trying to explain something so complicated in such a short area, here is a full informational explanation. http://spindrop.us/2007/03/03/php-double-versus-single-quotes/ http://www.weberdev.com/get_example-3750.html http://www.thescripts.com/forum/thread3954.html Those are some about single quote's versus double quote's. Below are some more that are related to escaping characters. http://www.java2s.com/Code/Php/String/String-Escape.htm Escapes are somewhat hard to explaining. Performing escapes for something you are putting in the database is the oposite. There are PHP escapes that are requried for a string to recognize what you are doing, like / to escape double quotes inside of double quotes. There is something different though for a database, data can't be put directly into a mysql database without being completely escaped within the string. Quote Link to comment https://forums.phpfreaks.com/topic/49445-solved-just-a-simply-question-about-quotes-inside-of-quotes/#findComment-242349 Share on other sites More sharing options...
trq Posted May 1, 2007 Share Posted May 1, 2007 There is something different though for a database There is nothing different for databases. Quotes need to be escaped so that your queries dont think your values have ended premiturely. Quote Link to comment https://forums.phpfreaks.com/topic/49445-solved-just-a-simply-question-about-quotes-inside-of-quotes/#findComment-242351 Share on other sites More sharing options...
bobleny Posted May 1, 2007 Author Share Posted May 1, 2007 Ah! Wonderful response! I will check that out when I get home! It will be interesting! Thanks to all! Quote Link to comment https://forums.phpfreaks.com/topic/49445-solved-just-a-simply-question-about-quotes-inside-of-quotes/#findComment-242353 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.