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不包含任何值
我叔叔的房子谁说过"我是柏林人"?
那么参数字符串将会非常混乱…
<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);