2013-04-27 91 views
0
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.'");">'; 

现在 - 这完全工作正常 - 如果$用品 - >报价和$用品 - >作者犯规持有任何值,如:字符串处理Java/HTML/PHP

我叔叔家 谁说“ICH bin ein Berliner“?

然后PARAMS字符串会被漂亮搞砸...

<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');"> 

回答

2

使用htmlspecialchars功能,将编码(逃跑)的特殊字符,例如"将成为&quot;

echo htmlspecialchars($item->quote); 
+0

对不起错误我编辑的代码 – PSR 2013-04-27 13:09:14

+0

没问题:)我还没有完成我的编辑代码,所以我重写它 – Zbigniew 2013-04-27 13:10:02