我有bellow字符串,其中包含内容和锚标记:
$string = 'I am a lot of text with <a href="#">links in it</a>';
Run Code Online (Sandbox Code Playgroud)
我想删除锚标记及其文本(链接在其中)
我试过strip_tags但它仍然是字符串中的锚文本,之后,我尝试过preg_replace这个例子:
$string = preg_replace('/<a[^>]+>([^<]+)<\/a>/i', '\1', $string);
Run Code Online (Sandbox Code Playgroud)
但得到相同的结果strip_tags.
在删除锚标签后,我只想要"我有很多文字".
任何的想法?
一种方法是使用.*通配符内<a和a>
$string = 'I am a lot of text with <a href="#">links in it</a>';
$string = preg_replace('/ <a.*a>/', '', $string);
echo $string;
Run Code Online (Sandbox Code Playgroud)
如果出现多个锚点,您可以使用.*?.制作你的模式'/ <a.*?a>/'
| 归档时间: |
|
| 查看次数: |
1262 次 |
| 最近记录: |