正如标题所说,当我使用strip_tags($text, "<a>...<others>")
和我插入超链接到$text
,我留下的<a>
而不是<a href='...'>
输出。我该如何解决这个问题,或者是否对此不够灵活?用strip_tags是保持<a>但剥离其属性
谢谢!
$text = ucfirst($text);
$text = preg_replace('/\v+|\\\r\\\n/', '<br />', $text);
$allow = '<p><br><ul><ol><li><strong><img><em><a>';
$text = strip_tags($text, $allow);
// now, remove any suspect tags, etc.
preg_match_all("/<([^>]+)>/i", $allow, $allTags, PREG_PATTERN_ORDER);
输入$text
是:
<p>Lorum ipsum <a href="http://www.test.com">This is a test link</a>.</p>
按照[PHP手册](http://php.net/manual/en/function.strip-tags.php),存在与''标签的示例,并且内的那些属性''标签被移除。你能发布你正在使用的确切字符串吗? –
请将您的代码和期望的结果与实际结果进行比较。 – Barmar
上面贴出的代码。谢谢! –