使用 PHP 查询路径删除 HTML 字符串顶部和底部的空标签



我正在使用php Querypath,我正在尝试从html字符串中删除html顶部和底部存在的所有空标签。例如:

      <div>&nbsp;</div>
      <div>&nbsp;</div>
      <div>I want remove empty div tag on top and bottom</div>
      <div>&nbsp;</div>
      <div>other content</div>
      <div>&nbsp;</div>
      <div>&nbsp;</div>

使用 php 查询路径,我希望更改为:

      <div>I want remove empty div tag on top and bottom</div>
      <div>&nbsp;</div>
      <div>other content</div>

我该怎么办?

使用替换字符串将div 替换为空格。

str_replace(find,replace,from);

因此,您可以在查找中使用<div>&nbsp;</div>,并将其替换为代码中的""

最新更新