加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

使用php替换正则表达式与正则表达式

发布时间:2020-12-13 17:30:01 所属栏目:PHP教程 来源:网络整理
导读:我想使用相同的哈希标签替换字符串中的哈希标签,但在添加链接之后 例: $text = "any word here related to #English must #be replaced." 我想替换每个主题标签 #English --- a href="bla bla"#English/a#be --- a href="bla bla"#be/a 所以outpu应该是这样
我想使用相同的哈希标签替换字符串中的哈希标签,但在添加链接之后

例:

$text = "any word here related to #English must #be replaced."

我想替换每个主题标签

#English ---> <a href="bla bla">#English</a>
#be ---> <a href="bla bla">#be</a>

所以outpu应该是这样的:

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

DEMO

OUTPUT:

any word here related to <a href='bla bla'>#English</a> must <a href='bla bla'>#be</a> replaced.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读