替换字符串中的 html 标记

Replace html markup in strings

如何替换包含混合内容的字符串中的 html 个元素,例如:

$str = "Find the   element in this string";

我想清除所有   ;字符串中的元素。所以,我尝试了:

str_replace(" ", " ", $str);

我知道   ;是 space 并呈现为空 space,但是有一个特定的原因我需要这样做与我拥有的其他数据库操作相关。

如果 str_replace 对 HTML 标签不起作用,我应该使用正则表达式吗?

$str = htmlentities($string, null, 'utf-8');
$str = str_replace(" ", "", $str);