如何用每个锚文本替换所有锚。我的代码是
$body='<p>The man was <a href="http://www.example.com/video/">dancing like a little boy</a> while all kids were watching ... </p>';
Run Code Online (Sandbox Code Playgroud)
我希望结果是:
<p>The man was dancing like a little boy while all kids were watching ... </p>
Run Code Online (Sandbox Code Playgroud)
我用了 :
$body= preg_replace('#<a href="https?://(?:.+\.)?ok.co.*?>.*?</a>#i', '$1', $body);
Run Code Online (Sandbox Code Playgroud)
结果是:
<p>The man was while all kids were watching ... </p>
Run Code Online (Sandbox Code Playgroud)