如何从字符串中删除<br />标签和更多?

3 php

我需要删除所有<br />和所有'引号'(")和所有'ands'(&)并用空格替换它们......

我怎样才能做到这一点?(在PHP中)

我试过这个<br />:

   $description = preg_replace('<br />', '', $description);
Run Code Online (Sandbox Code Playgroud)

但它<>代替了每一个<br />......

谢谢

小智 10

<?php

$text = '<p>Test paragraph.</p><!-- Comment --> <a href="#fragment">Other text</a>';
echo strip_tags($text);
echo "\n";
// Allow <p> and <a>
echo strip_tags($text, '<p><a>');

?>
Run Code Online (Sandbox Code Playgroud)

http://php.net/manual/en/function.strip-tags.php


Vin*_*nie 5

您可以像这样使用str_replace

  str_replace("<br/>", " ", $orig );
Run Code Online (Sandbox Code Playgroud)

preg_replace 等使用正则表达式,这可能不是您想要的。


Gor*_*don 5

如果str_replace()不是为您工作,那肯定有其他问题,因为

$string = 'A string with <br/> & "double quotes".';
$string = str_replace(array('<br/>', '&', '"'), ' ', $string);
echo $string;
Run Code Online (Sandbox Code Playgroud)

输出

A string with      double quotes .
Run Code Online (Sandbox Code Playgroud)

请提供输入字符串的示例,以及过滤后的预期效果。