在PHP中转义双引号 [英] Escaping double quotes in php
问题描述
我有以下变量由用户生成的内容动态设置:
I have the following variable being dynamically set by user generated content:
$variable = '<a href="http://www.mysite.com/article">This Article</a>';
设置此变量后,我将其回显
When this variable is set, I then echo it as such
echo $variable;
我知道这是无效的,因为我需要转义双引号等.
I know that as is, this wouldn't be valid because I would need to escape the double quotes etc.
有没有一种方法可以自动执行该过程,以使变量可打印为可点击链接,从而自动将变量中的引号转义?
Is there a way to automate the process to make the variable printable as a clickable link, thus escaping the quotes in my variable automatically?
事实证明,这确实是完全有效的,但是在joomla网站上使用了该代码,删除了html标签,我必须使用[[a href]]而不是常规的<>. 谢谢大家的帮助!
Turns out this is indeed perfectly valid, but this being used on a joomla site, html tags are being stripped out, and I have to use [[a href]] instead of the regular <>. Thanks everyone for your help!
推荐答案
我尝试在您拥有的php页面中使用您的确切代码,并且它可以按您的需要进行操作.似乎对我来说很好.
I tried to use your exact code in a php page I have and it acts as you need it to. Seems to be working just fine for me.
这篇关于在PHP中转义双引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!