Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Echo syntax error with single quote or double quotes?

Tags:

php

The is a very simple echo statement but I can't solve it?

echo '"What is your name?'";
like image 499
Starx Avatar asked Jun 07 '10 05:06

Starx


People also ask

What is the difference between using double quote single quote with echo command in PHP?

In PHP, people use single quote to define a constant string, like 'a' , 'my name' , 'abc xyz' , while using double quote to define a string contain identifier like "a $b $c $d" . echo "my $a"; This is true for other used of string.

How do you echo a single quote?

`echo` command prints the value of this variable without any quotation. When the variable is quoted by single quote then the variable name will print as output. If the backslash ( \ ) is used before the single quote then the value of the variable will be printed with single quote.

Can you use single quotes in PHP?

Single quoted ¶The simplest way to specify a string is to enclose it in single quotes (the character ' ). To specify a literal single quote, escape it with a backslash ( \ ). To specify a literal backslash, double it ( \\ ).


1 Answers

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

like image 74
Sarfraz Avatar answered Nov 07 '22 19:11

Sarfraz