php preg_replace all the link with #

2019-09-21 14:57发布

there are more words in a text, some are english, some are latins, now, how to use preg_replace, broken all the links with #? make something like:

<a href="#next">flow to the next</a> => flow to the next ? (only broken the links with # in a long text.

Thanks.

not work for this.

$new = preg_replace('/<a(?:.*?)(href="#)(?:.*?)>(.*?)<\/a>/is', '$2', $old); 
// this will also broken other links...

1条回答
Bombasti
2楼-- · 2019-09-21 15:42
<?php
$old = '<a href="#next">flow to the next</a> ';
$new = preg_replace('/(<a href="\#.*?">)(.*?)<\/a>/is', '$2', $old); 
echo $new;

demo

查看更多
登录 后发表回答