我在php字符串中有一个html标签,如何从该字符串中分离每个标签? 例如:
$html = '<p><img class="alignnone wp-image-1665" src="http://doneetjee.in/wp-content/uploads/2018/11/128a-300x135.jpg" alt="" width="220" height="99" /></p><p>As the belt does not slip,</p><p><img src="http://latex.codecogs.com/gif.latex?\therefore&space;\,\,\,\,&space;v_A&space;=&space;v_B" alt="\therefore \,\,\,\, v_A = v_B" align="absmiddle" /></p><p>or';
我希望结果像这样:
"<Image> http://doneetjee.in/wp-content/uploads/2018/11/128a-300x135.jpg <\Image>
As the belt does not slip,
<Formula> \therefore \,\,\,\, v_A = v_B <\Formula>"
答案 0 :(得分:0)
尝试添加转义序列字符,例如, \ n换行 \ t用于tbl空间等。
示例。
谢谢...
答案 1 :(得分:0)
简单的功能,只是它将在每个>标记后替换为\ n
$ html = str_replace(“>”,“> \ n”,$ html);
echo $ html;