Php 无法从多字节输入中剥离HTML标记
我有一个函数可以帮助从输入中去除HTML标记,如下所示 PHPPhp 无法从多字节输入中剥离HTML标记,php,preg-replace,multibyte,Php,Preg Replace,Multibyte,我有一个函数可以帮助从输入中去除HTML标记,如下所示 PHP function strip_html_tags2( $str ) { $var_search = array( // Remove invisible content '@<head[^>]*?>.*?</head>@siu', '@<style[^>]*?>.*?</style&
function strip_html_tags2( $str )
{
$var_search = 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',
// Add line breaks before and after blocks
'@</?((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',
);
$var_replace = array(
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
"\n\$0", "\n\$0", "\n\$0", "\n\$0", "\n\$0", "\n\$0",
"\n\$0", "\n\$0",
);
//$str = html_entity_decode($str, ENT_QUOTES, 'UTF-8');
$str = preg_replace("/&#?[a-z0-9]+;/i"," ", $str);
$str = preg_replace( $var_search, $var_replace, $str );
return strip_tags( $str );
}
function strip\u html\u tags2($str)
{
$var\u search=数组(
//删除不可见内容
'@]*?>.'@siu',
'@]*?>.'@siu',
“@]*?*?*?@siu”,
“@]*?*?*?@siu”,
“@]*?*?*?@siu”,
"@
任何建议都将不胜感激。我刚刚测试了此功能,并对您提供的输入运行了该功能,结果是相同的文本,但是
和被\n
替换。换句话说,它听起来正是您想要的。请检查此功能。您的代码按预期工作,那么问题是什么。我如果将输入存储到变量中,它将工作,但通过POST输入时它将不工作。上面添加了演示页。@wkyip在这种情况下,请显示您如何调用该函数。可能是您使用了$\u POST
错误。如果没有调用该函数的代码,我们将猜测出了什么问题。另外,仅供参考,如果您回复某人的com注意,你应该在评论中包括他们的用户名(就像我在这里对你的用户名所做的那样)。这样,它会通知他们你已经回复了。否则,他们不会知道你说了什么。我只是碰巧看到了你的评论;否则,我永远不会知道。
<p>If you’ve had a website up since at least the beginning of the year...</p>