如何在PHP中的双引号中使用单引号? [英] How to use single quotes within double quotes in PHP?
本文介绍了如何在PHP中的双引号中使用单引号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在PHP中创建链接:
echo "<a href=\"$currentFile?rowID=$row['id']\">click here</a>";
这将引发错误:解析错误:解析错误,期望为"T_STRING"或"T_VARIABLE"或"T_NUM_STRING"
.你该怎么做?
This throws an error: Parse error: parse error, expecting 'T_STRING' or 'T_VARIABLE' or 'T_NUM_STRING'
. How can you do this?
此外,混合使用单引号和双引号以及转义双引号会降低可读性并始终会产生错误.有没有更好的方法来用其他语法创建引号,例如Ruby中的%Q()?
Also, mixing single and double quotes, and escaping double quotes reduces readability and always generates errors. Is there a better way to create quotes with another syntax, like %Q() in Ruby?
正在使用PHP 5.2.8.
Working PHP 5.2.8.
推荐答案
问题是您的数组变量插值.语法可以是
The problem is your array variable interpolation. The syntax is either
"$row[id]"
或
"{$row['id']}"
所以:
"<a href=\"$currentFile?rowID=$row[id]\">click here</a>"
请参见 http://php.net/manual/zh-CN/language.types.string.php#language.types.string.parsing .
这篇关于如何在PHP中的双引号中使用单引号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文