-4
<ul class="c2">
    <li><a href="hire-project-manager/">Hire Project Manager </a></li>
    <li><a href="hire-ios-developer/"> Hire iPhone Developer </a></li>
    <li><a href="hire-ios-developer/">  Hire iPad Developer </a></li>
    <li><a href="hire-android-developer/">Hire Android Developer </a></li>
    </li>
    <li><a href="hire-3d-artist/">Hire 3D Artist</a></li>
</ul>
</div>
<h1>Get In Touch With Us</h1>
<div class="copyright-footer">Copyright &copy; All rights reserved  </div>

我有以下这些html,我想删除额外的空格并需要类似的结果:

<ul class="c2">
    <li><a href="hire-project-manager/">Hire Project Manager</a></li>
    <li><a href="hire-ios-developer/">Hire iPhone Developer</a></li>
    <li><a href="hire-ios-developer/">Hire iPad Developer</a></li>
    <li><a href="hire-android-developer/">Hire Android Developer</a></li>
    </li>
    <li><a href="hire-3d-artist/">Hire 3D Artist</a></li>
</ul>
</div>
<h1>Get In Touch With Us</h1>
<div class="copyright-footer">Copyright &copy; All rights reserved</div>

谁能帮助我在 PHP 和 preg、str_replace 等的帮助下解决这个问题

4

1 回答 1

0

删除[\n\t\r\ ]标签开始后文本开头的空格:

$html=preg_replace('/>\s+/','>',$html);

删除[\n\t\r\ ]标签前文本末尾的空格:

$html=preg_replace('/\s+</','<',$html);
于 2013-01-30T16:03:29.460 回答