我想用相同的散列标签替换字符串中的散列标签,但是在添加链接之后
例子:
$text = "any word here related to #English must #be replaced."
我想用
替换每个主题标签#English ---> <a href="bla bla">#English</a>
#be ---> <a href="bla bla">#be</a>
所以输出应该是这样的:
$text = "any word here related to <a href="bla bla">#English</a> must <a href="bla bla">#be</a> replaced."
最佳答案
$input_lines="any word here related to #English must #be replaced.";
preg_replace("/(#\w+)/", "<a href='bla bla'>$1</a>", $input_lines);
输出:
any word here related to <a href='bla bla'>#English</a> must <a href='bla bla'>#be</a> replaced.
关于php - 使用 PHP 将正则表达式替换为正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22040272/