在PHP中使用单引号(转义) [英] Using single quotes (escaping) in PHP
本文介绍了在PHP中使用单引号(转义)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在PHP代码中编写HTML代码。已经为锚标记样式编写,如果我改变了一些部分会影响。所以我正在尝试在跨度onclick事件中写入我的代码。这是我的代码
I am writing HTML code inside PHP tags. Already for anchor tag styling is written and if I change some parts will affect. So I am trying to write my code inside the span onclick event. Here is my code
<div>
<span style='cursor:pointer;' onclick='window.location.href='www.google.com'>
".$array1[$i] ['name']."
</span>
</div>
如果单击该数组[名称],则应该转到google.com。问题是我用来提及我的URL的单引号。如何在此事件中转义字符串?
If that array[name] is clicked, it should go to google.com. The problem is the single quotes I used for mentioning my URL. How do I escape strings in this event?
推荐答案
$strLocation = 'http://www.google.com';
$strLink = "<span onclick='window.location.href='".$strLocation."''>HI there</span>";
(or)
$strLink = '<span onclick="window.location.href=\''.$strLocation.'\'">HI there</span>';
print $strLink;
使用&#39;
是一个HTML特殊字符在字符串操作期间未被检测到,并且只会出现在浏览器中。
Using '
is an HTML special character which remains undetected during string operations and will appear only in the browser.
使用 \
字符串。
这篇关于在PHP中使用单引号(转义)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文