Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

my new defination is

$var="Tony said:"I like this game!""

It appeared that only

"Tony said:"

part can be recoginized, but I need the whole sentence. What can I do?

share|improve this question
up vote 4 down vote accepted

A simple solution is to just double the quotes. See the link for other options.

$var="Tony said:""I like this game!"""
share|improve this answer
Thank you very much. It works. – pansal Sep 7 '11 at 8:30

Just for completness, alternative solutions are to use the escape character:

$var= "Tony said:\`"I like this game!\`""

or "here strings" which are normally useful for multi-line texts but can be used for this case as well:

Tony said:"I like this game!"
share|improve this answer

Even easier: single quotes. You can put any number of double quotes in a single-quote string, or vice versa:

 $var = 'Tony said, "I like this game!"'


 $var = "Tony said, 'I like this game!'"

I personally think this is the easiest and most readable solution.

share|improve this answer
Worth noting that variables within single quotes will not be evaluated. – jscott Sep 9 '11 at 1:31
Good point. That's the fundamental difference between single and double quotes -- single quotes will treat all internal text literally, whereas double quotes will expand variables [or expressions enclosed in $()]. – jbsmith Sep 9 '11 at 16:30

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.