kha*_*lil 3 php regex preg-replace
如何用每个锚文本替换所有锚。我的代码是
$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)
尝试这个
$body='<p>The man was <a href="http://www.example.com/video/">dancing like a little boy</a> while all kids were watching ... </p>';
echo preg_replace('#<a.*?>([^>]*)</a>#i', '$1', $body);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1160 次 |
| 最近记录: |