小编kha*_*lil的帖子

preg_replace href 锚点与锚文本

如何用每个锚文本替换所有锚。我的代码是

$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)

php regex preg-replace

3
推荐指数
1
解决办法
1160
查看次数

标签 统计

php ×1

preg-replace ×1

regex ×1