使用htmlspecialchars()仅转义单引号(不留双引号) [英] Escape only single quotes (leave double quotes alone) with htmlspecialchars()
本文介绍了使用htmlspecialchars()仅转义单引号(不留双引号)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道还有其他仅对单引号进行转义的方法(例如这样的答案),但在我看来应该有一种使用 htmlspecialchars( 。
I know there are other ways of of escaping only single quotes (such as this answer), but it appears to me that there should be a way using htmlspecialchars().
根据手册,它应该是它们常数的某种组合,但是根据他们的解释,我看不到它。
According to the manual, it should be some combination of their constants, but based on their explanations, I don't see it.
是否可以使用 htmlspecialchars()
只对单引号进行转义,而忽略双引号?
Is it possible to escape only single quotes, leaving the double quotes alone, with htmlspecialchars()
?
推荐答案
str_replace("'", "\\'", $string);
在那里。
或者,使用 ENT_QUOTES
htmlspecialchars($string, ENT_QUOTES);
这篇关于使用htmlspecialchars()仅转义单引号(不留双引号)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文