【发布时间】:2019-08-06 10:40:33
【问题描述】:
我在 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>"
【问题讨论】:
-
如果输入是有效的 HTML,你应该考虑使用 PHP 的 DOMDocument
-
可以发送代码...!
-
我不明白你的评论是什么意思。
-
这是我的代码loadHTML('
doneetjee.in/wp-content/uploads/2018/11/128a-300x135.jpg" alt="" width="220" height="99" />
由于皮带不打滑,latex.codecogs.com/gif.latex?\therefore&space;\,\,\,\,&space;v_A&space;=&space ;v_B" alt="\因此\,\,\,\, v_A = v_B" align="absmiddle" />
或'); $xml = simplexml_import_dom($doc); $images = $xml->xpath('//p');打印_r($图像); foreach ($images as $img) { echo $img; } ?>
-
请edit您的问题包括所有相关代码和信息。当您在 cmets 中编写大代码块时,它非常难以阅读。
标签: php html-parsing