Php 从用户以html格式存储的数据中剥离html标记
我在这个项目上工作,在主页面上我们显示用户的详细信息,每个用户自己更新自己的详细信息,我们还允许详细的HTML标记 但我面临的问题是,如果人们添加一些HTML细节,比如Php 从用户以html格式存储的数据中剥离html标记,php,Php,我在这个项目上工作,在主页面上我们显示用户的详细信息,每个用户自己更新自己的详细信息,我们还允许详细的HTML标记 但我面临的问题是,如果人们添加一些HTML细节,比如 <p><span style="color:#4c4c4c;font-family:Verdana;">Graphic Designer. Contact ***** .</span></p> 这对我不起作用,我还编写了自己的函数来剥离主页上的这些标签 function stri
<p><span style="color:#4c4c4c;font-family:Verdana;">Graphic Designer. Contact ***** .</span></p>
这对我不起作用,我还编写了自己的函数来剥离主页上的这些标签
function strip_html_tags( $text )
{
$text = preg_replace(
array(
// Remove invisible content
'@<head[^>]*?>.*?</head>@siu',
'@<style[^>]*?>.*?</style>@siu',
'@<script[^>]*?.*?</script>@siu',
'@<object[^>]*?.*?</object>@siu',
'@<embed[^>]*?.*?</embed>@siu',
'@<applet[^>]*?.*?</applet>@siu',
'@<noframes[^>]*?.*?</noframes>@siu',
'@<noscript[^>]*?.*?</noscript>@siu',
'@<noembed[^>]*?.*?</noembed>@siu',
'@</?((address)|(blockquote)|(center)|(del))@iu',
'@</?((div)|(h[1-9])|(ins)|(isindex)|(p)|(pre))@iu',
'@</?((dir)|(dl)|(dt)|(dd)|(li)|(menu)|(ol)|(ul))@iu',
'@</?((table)|(th)|(td)|(caption))@iu',
'@</?((form)|(button)|(fieldset)|(legend)|(input))@iu',
'@</?((label)|(select)|(optgroup)|(option)|(textarea))@iu',
'@</?((frameset)|(frame)|(iframe))@iu',
),
array(
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',"$0", "$0", "$0", "$0", "$0", "$0","$0", "$0",), $text );
return strip_tags( $text);
}
function strip\u html\u标记($text)
{
$text=preg\u replace(
排列(
//删除不可见内容
'@]*?>.'@siu',
'@]*?>.'@siu',
“@]*?*?*?@siu”,
“@]*?*?*?@siu”,
“@]*?*?*?@siu”,
“@]*?*?*?@siu”,
“@]*?*?*?@siu”,
“@]*?*?*?@siu”,
“@]*?*?*?@siu”,
“@内置于PHP中
更强大的解决方案您是否考虑过简单地使用html\u entities()
?除其他外,这将“”替换为“”。它允许您将其回显到页面,而不必担心它会干扰页面。您的个人信息是否不仅仅保存为实体而不是纯文本?这就解释了为什么strip\u标记不起作用
在这种情况下,使用:显示实际的HTML为什么没有strip_标记()
工作?请发布您使用的代码。为什么剥离标签对您不起作用,您有什么问题吗?既然如此,为什么不干脆用htmlentities来逃避输出呢?HTMLPurifier很棒,但他想完全剥离HTML(即根本不允许),所以htmlentities/specialchars可以工作。
strip_tags
function strip_html_tags( $text )
{
$text = preg_replace(
array(
// Remove invisible content
'@<head[^>]*?>.*?</head>@siu',
'@<style[^>]*?>.*?</style>@siu',
'@<script[^>]*?.*?</script>@siu',
'@<object[^>]*?.*?</object>@siu',
'@<embed[^>]*?.*?</embed>@siu',
'@<applet[^>]*?.*?</applet>@siu',
'@<noframes[^>]*?.*?</noframes>@siu',
'@<noscript[^>]*?.*?</noscript>@siu',
'@<noembed[^>]*?.*?</noembed>@siu',
'@</?((address)|(blockquote)|(center)|(del))@iu',
'@</?((div)|(h[1-9])|(ins)|(isindex)|(p)|(pre))@iu',
'@</?((dir)|(dl)|(dt)|(dd)|(li)|(menu)|(ol)|(ul))@iu',
'@</?((table)|(th)|(td)|(caption))@iu',
'@</?((form)|(button)|(fieldset)|(legend)|(input))@iu',
'@</?((label)|(select)|(optgroup)|(option)|(textarea))@iu',
'@</?((frameset)|(frame)|(iframe))@iu',
),
array(
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',"$0", "$0", "$0", "$0", "$0", "$0","$0", "$0",), $text );
return strip_tags( $text);
}