0
preg_replaceを使用するには、class="country"
のリンクをすべて削除し、リンクのテキストのままにします。php preg_replace
<a href="XXXXXX" class="country">TEXT</a>
=> TEXT以下preg_replace
を変更する方法
?
$str = <<<EOT
Long long ago, there was a poor boy named <a href="index1.html">John</a>. Who was living in <a href="index2.html">Liverpoor</a>, a city of <a href="index3.html" class="country">england</a>.
EOT;
$result= preg_replace('/<a(.*?)class="country"(.*?)>(.*?)<\/a>/i','$3',$str);
echo $result;
// I want get the result as: "Long long ago, there was a poor boy named <a href="index1.html">John</a>. Who was living in <a href="index2.html">Liverpoor</a>, a city of england"
代わりに、DOMパーサを使用してご検討ください。 'england'は削除すべき唯一のリンクテキストです。 – Nik
@Nik、いいえ、私のコードはすべてのリンクを壊しました。私はまだ他のリンクのままにしたい、 'class =" country "' –