简体   繁体   English

PHP的回声引号错误

[英]php echo quotation marks error

I'm having hard time with quotation marks. 我很难用引号引起来。 I have this line of code; 我有这行代码;

echo "<a href='$bName'_read.php?bid='$bid'&id='$next_id[id]'>NEXT</a>";

with 3 variables, $bName , $bid , and $next_id[id] . 有3个变量, $bName$bid$next_id[id]

There is something wrong with the quotations I've used. 我使用的报价有问题。 I also tried this; 我也尝试过

echo "<a href='".$bName."_read.php?bid=".$bid."&id=".$next_id['id']."'">";

but it's still not working. 但仍然无法正常工作。

Can anyone explain how quoting works in this case please? 有人可以在这种情况下解释报价的原理吗?

You don't need to put single quotes around every PHP variable. 您无需在每个PHP变量周围都加上单引号。 It should make sense in HTML instead, for example; 例如,它应该在HTML中有意义;

echo "<a href='{$bName}_read.php?bid={$bid}&amp;id={$next_id['id']}'>NEXT</a>";

You need curly braces ( {} ) around object and array variables, but it is also useful for normal variables. 您需要在对象和数组变量周围使用花括号( {} ),但对于普通变量也很有用。 Also, the array index should be in quotes as it is a string (not required for integer indexes). 另外,数组索引应该是双引号,因为它是一个字符串(整数索引不需要)。

Additionally, I changed the ampersand ( & ) to &amp; 此外,我改变了符号( & )到&amp; as & signifies the start of a special character code (just like &amp; ), so although in this case it wouldn't be a problem it is best practice to put the HTML char code in, even in a URL. as &表示特殊字符代码的开始(就像&amp; ),因此尽管在这种情况下不会有问题,但最好的做法是将HTML字符代码(即使是URL)也放入其中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM