echo '<button class="modalInput" title="Is there an error in this question, report it here." rel="#prompt" onClick="params('.$item->catid.','.$item->id.',"'.$item->quote.'","'.$item->author.'");">';
现在 - 这工作得很好 - 如果 $item->quote 和 $item->author 不包含任何值,例如:
我叔叔家 谁说“Ich bin ein Berliner”?
那么参数字符串就会变得非常困惑......
<button class="modalInput" title="Is there an error in this question, report it here." rel="#prompt" onClick="params(21,12,"Who said "ich bin ein Berliner"","George Bush");">
我该如何解决这个问题?
<小时 />还是不行
echo '<button class="modalInput" title="Is there an error in this question, report it here." rel="#prompt" onClick="params('.$item->catid.','.$item->id.',\''.htmlspecialchars($item->quote).'\',\''.(string) htmlspecialchars($item->author).'\');">';
变成
<button class="modalInput" title="Is there an error in this question, report it here." rel="#prompt" onClick="params(29,29,'In a FOX TV show, what did 'The OC' stand for','Orange County');">
请您参考如下方法:
使用htmlspecialchars
函数,它将编码(转义)特殊字符,例如"
将变为 "
:
echo htmlspecialchars($item->quote);