PHP preg_replace - 删除ul,li标签之间的BR标签
问题描述:
我想创建一个regex,它将删除ul/ol li标签之间的所有BR标签。例如:PHP preg_replace - 删除ul,li标签之间的BR标签
Test<br>
<ul>
<li>
Test<br>
</li>
</ul>
我要得到这样的结果:
Test<br>
<ul>
<li>
Test
</li>
</ul>
我尝试使用此代码:
$param_array['description'] = preg_replace('/(?<=<ul>|<\/li>)([\s*<br>\s*|\s*<br\/>\s*|\s*<br \/>\s*]+)(?=<\/ul>|<li>)/is', "$1$3", $param_array['description']);
$param_array['description'] = preg_replace('/(?<=<ol>|<\/li>)([\s*<br>\s*|\s*<br\/>\s*|\s*<br \/>\s*]+)(?=<\/ol>|<li>)/is', "$1$3", $param_array['description']);
,但它不工作。任何人都可以帮助我?
答
使用str_replace()函数函数删除的
:)
<?php
$html = "Test<br>
<ul>
<li>
Test<br>
</li>
</ul>";
$without_breaks = str_replace(array('<br>', '&', '"'), ' ', $html);
?>
你的代码的任何情况下,将我所有的代码删除所有BR标签。我想只有剥去之间的UL/OL标签BR标签,所以:'
- HERE_I_WANT_REMOVE_BR_TAGS
但在这里我要ALLOW BR标签' –
', '&', '“ '),'',$ HTML2); $ finalhtml = $ HTML1 $ without_breaks; 回声$ finalhtml; > – Andrew1996
没有评论...,, –