Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在单引号PHP中显示双引号_Php_String - Fatal编程技术网

如何在单引号PHP中显示双引号

如何在单引号PHP中显示双引号,php,string,Php,String,我有一个PHP echo语句: echo "stores[".$row['BarID']."] = [". $row['BarName'] . ", " . $row['Address']. ",". $row['City']. "," . $row['State']. " 0". $row['ZipCode']. "," . $row['PhoneNumber']. ",". $row['Lattitude']. ",".$row['Longitude']. "]". ";<br>

我有一个PHP echo语句:

echo "stores[".$row['BarID']."] = [". $row['BarName'] . ", " . $row['Address']. ",". $row['City']. "," . $row['State']. " 0". $row['ZipCode']. "," . $row['PhoneNumber']. ",". $row['Lattitude']. ",".$row['Longitude']. "]". ";<br>";  
但我希望输出为双引号,例如:

stores[0]=["The Ale 'N 'Wich Pub", "246 Hamilton St, New Brunswick, NJ 08901", "732-745-9496 Specialty: Sport", "40.4964198", "-74.4561079"];
我在PHP网站上看过PHP字符串函数手册,但仍然不明白如何实现它。谢谢你的帮助

您错过的关键字是“转义”(请参阅)。最简单的例子:

echo "\"";
将输出:

"
编辑

基本的解释是-如果你想把双引号放在双引号结束的字符串中,你必须转义它,否则你会得到语法错误

例如:

echo "foo"bar";
         ^
         +- this terminates your string at that position so remaining bar"
            causes syntax error. 
要避免这种情况,您需要避开双引号:

echo "foo\"bar";
         ^
         +- this means the NEXT character should be processed AS IS, w/o applying
            any special meaning to it, even if it normally has such. But now, it is
            stripped out of its power and it is just bare double quote.
因此,您的(这是字符串的一部分,但您应该抓住要点,自己完成其余的工作):

应该是:

 echo "stores[".$row['BarID']."] = [\"". $row['BarName'] . "\", \"" . $row['Address']. "\"

诸如此类。

你介意用我在问题中的例子向我展示一下它的样子吗。谢谢
 echo "stores[".$row['BarID']."] = [". $row['BarName'] . ", " . $row['Address'] .
 echo "stores[".$row['BarID']."] = [\"". $row['BarName'] . "\", \"" . $row['Address']. "\"