Jump to content

[SOLVED] Just a simply question about quotes inside of quotes...


bobleny

Recommended Posts

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....

Link to comment
Share on other sites

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!";

Link to comment
Share on other sites

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.';

Link to comment
Share on other sites

<?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!");
?>

Link to comment
Share on other sites

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... :'(

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.