[英]How do you show double quotes in single quotes PHP
我有一個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 ,40.4964198,-74.4561079];
但是我會像下面這樣在雙行中顯示輸出:
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字符串函數手冊》,但仍然不了解如何實現它。 感謝您的幫助。
您錯過的關鍵字是“轉義”(請參閱Wiki )。 最簡單的例子:
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']. "\"
等等。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.