The is a very simple echo statement but I can't solve it?
echo '"What is your name?'";
Jeff Atwood
64.1k48 gold badges152 silver badges153 bronze badges
asked Jun 7, 2010 at 5:24
-
12Why does stuff like this get voted down?Daniel Harms– Daniel Harms2010年06月07日 05:28:06 +00:00Commented Jun 7, 2010 at 5:28
-
9@Precision I can't really see how this question could help anyone else. What would they search for to find this? "my code is wrong"? Even rewording the question to make it useful is pointless. If someone knew what to search for (eg "mismatched quotes"), then they would have already solved their problem. Even the most basic of debugging (eg just looking at your syntax highlighting) would show the error here. We all have dumb errors like this which you can't figure out straight away, and I don't think there's anything wrong with asking it, but it's pretty obvious why it'd get voted down.nickf– nickf2010年06月07日 07:14:46 +00:00Commented Jun 7, 2010 at 7:14
-
@nickf I agree, but the answerers seem to enjoy this one, so I gave it my best shot as a title editJeff Atwood– Jeff Atwood2010年06月07日 08:46:52 +00:00Commented Jun 7, 2010 at 8:46
-
@Jeff you've made it much worse. Because there are very popular terrible rumor about a question you made a title. While the question itself was about syntax error, not quote styles.Your Common Sense– Your Common Sense2010年06月07日 08:50:35 +00:00Commented Jun 7, 2010 at 8:50
-
@col good point, I added "syntax error"Jeff Atwood– Jeff Atwood2010年06月07日 08:58:15 +00:00Commented Jun 7, 2010 at 8:58
6 Answers 6
Mismatch of single quotes, use this:
echo '"What is your name?"';
Your first enclosing character was single quote but ending one was double quote causing the problem
answered Jun 7, 2010 at 5:25
Sign up to request clarification or add additional context in comments.
Comments
Incorrect:
echo '"What is your name?'";
^ Unexpected character
Correct:
echo '"What is your name?';
Correct:
echo "What is your name?";
Correct:
echo 'What is your name?';
Correct:
echo '"What is your name?"';
Correct:
echo "'What is your name?'";
answered Jun 7, 2010 at 5:37
3 Comments
nickf
@Sarfraz - how do you figure that? How do you know he doesn't want the single quotes in the string?
Sarfraz
@nickf: I did not say he doesn't want single quotes, I meant he needs his string inside the double quotes something that can be seen from his code, only that he placed ending single quotes wrongly, basically he seems to echo it like this
"What is your name?", see double quotes included in the output. Something that can be figured out from his code '"What is your name?"';nickf
@sarfraz:
only that he placed ending single quotes wrongly .. or the starting single quotes were placed wrongly...Your quotes are nested incorrectly.
answered Jun 7, 2010 at 5:27
Comments
echo "\"What is your name?\"";
Andrew
20.4k13 gold badges110 silver badges122 bronze badges
answered Jun 7, 2010 at 6:48
Comments
This is where your interpreter is choking:
echo '"What is your name?'";
expecting ; not "
answered Jun 7, 2010 at 6:03
Comments
echo "What is your name?";
This is Simply the best. No confusion No problem..:)
Starx
79.3k50 gold badges187 silver badges265 bronze badges
Comments
lang-php