Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 带标签保留<;a>;但剥离了它的属性_Php_Formatting_String Formatting_Strip Tags - Fatal编程技术网

Php 带标签保留<;a>;但剥离了它的属性

Php 带标签保留<;a>;但剥离了它的属性,php,formatting,string-formatting,strip-tags,Php,Formatting,String Formatting,Strip Tags,正如标题所说,当我使用strip_标记($text,“…”)并在$text中插入超链接时,我的输出是,而不是。我该如何解决这个问题,或者带标签不够灵活吗 谢谢 $text = ucfirst($text); $text = preg_replace('/\v+|\\\r\\\n/', '<br />', $text); $allow = '<p><br><ul><ol><li><strong><img>

正如标题所说,当我使用
strip_标记($text,“…”)
并在
$text
中插入超链接时,我的输出是
,而不是
。我该如何解决这个问题,或者
带标签
不够灵活吗

谢谢

$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);
删除所有html元素或包含在
中的任何内容

从:

strip_tags-从字符串中剥离HTML和PHP标记

例如:

$text = '<p>Test paragraph.</p><!-- Comment --> <a href="#fragment">Other text</a>';

它应该像你想要的那样工作

$text = '<a href="http://www.someplace.com">link</a> <others>stuff</others>';
echo strip_tags($text,"<a>");
$text='stuff';
echo strip_标签($text,“东西
工作示例:


更新:对于您在更新的问题中发布的代码,我在这里运行了它,它仍然提供完整的

,根据,有一个示例,这些
标记中的
标记和属性被删除。您可以发布您正在使用的确切字符串吗?请发布您的代码和所需的属性结果与实际结果对比。代码张贴在上面。谢谢!
Test paragraph. Other text
$text = '<a href="http://www.someplace.com">link</a> <others>stuff</others>';
echo strip_tags($text,"<a>");
<a href="http://www.someplace.com">link</a> stuff