使用 preg_replace 删除某些内容

remove certain things using preg_replace

我的字符串:

Hi there!<div><br></div><img src="../images/Character Green.png"><div><br></div><div>Yes hello</div>

我只想显示文字 - 在这种情况下,它将是“你好!”和“是的你好

我想我需要使用 preg_replace

在这种情况下你可以使用strip_tags函数

echo strip_tags($s); // Hi there!Yes hello

或者用<br>标签分词有点复杂

$res = array_filter(explode('<br>', strip_tags($s, '<br>')));
echo implode(' ', $res); // Hi there! Yes hello