特定の HTML ドキュメントからすべてのアスタリスクを削除したいと考えています。ただし、ul-tag 内にあるもののみ。これらの ul-tag の中には、クラスを持つものもあります。何時間も自分自身を試した後、私は尋ねることにしました。
助けてくれてありがとう。
これを試すことができますか:
<ul[^>]*?>(.*?[*]+.*?)*</ul>
必要なものは次のとおりです。
<?php
// a function to remove any asterisks from a string
function replace_asterisks($replace){
return str_replace('*', '', $replace[0]);
}
$html = '* blah blah * * <ul>blah<li>*</li>*</ul> sad sad <ul>**</ul>';
// if found any <ul> with asterisks, pas the part to that function to remove asterisks from it
$html = preg_replace_callback('/<ul.*?>.*?\*.*?.*?<\/ul>/', 'replace_asterisks', $html);
echo $html;
?>