strip_tags不允许<<和>>在PHP中

时间:2016-09-13 08:17:15

标签: php mpdf

您好我想在php

中使用strip_tags在字符串中允许html标记

但我的字符串包含“<<”和“>>”我试图使用下面的代码允许这些东西:

$allowTags = "<<>><span><s><strike><del><bdo><big><small><ins><cite><acronym><font><sup><sub><b><u><i><a><strong><em><code><samp><tt><kbd><var><q><table><thead><tfoot><tbody><tr><th><td><ol><ul><li><dl><dt><dd><form><input><select><textarea><option><div><p><h1><h2><h3><h4><h5><h6><pre><center><blockquote><address><hr><img><br><indexentry><indexinsert><bookmark><watermarktext><watermarkimage><tts><ttz><tta><column_break><columnbreak><newcolumn><newpage><page_break><pagebreak><formfeed><columns><toc><tocentry><tocpagebreak><pageheader><pagefooter><setpageheader><setpagefooter><sethtmlpageheader><sethtmlpagefooter><annotation><template><jpgraph><barcode><dottab><caption><textcircle><fieldset><legend><article><aside><figure><figcaption><footer><header><hgroup><nav><section><mark><details><summary><meter><progress><time>";

$test = "<span>white</span>red<<blue";
file_put_contents("test.log", print_r($test,true),FILE_APPEND);
$text = strip_tags($test, $allowTags);
file_put_contents("test.log", print_r($text,true),FILE_APPEND);

但它不起作用我输出为<span>white</span>red,预期输出为<span>white</span>red<<blue

请帮我解决这个问题。提前谢谢。

1 个答案:

答案 0 :(得分:0)

<<不是标记,您必须使用正则表达式(例如preg_replace())或str_replace()来逃避它。