php删除单词以#开头

时间:2016-03-07 04:30:14

标签: php

我想在内容中删除以#开头的单词。

例如

$content  = "#test Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry #test2 standard dummy text ever since the 1500s, when an unknown printer took a galley of type #test3 and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. #test4 It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum #test5."

这里#test1,#test2,#test3,#test4,#test5是#words。我想删除那些话。

我使用preg_replace。但它没有得到输出。

请帮帮我。感谢

2 个答案:

答案 0 :(得分:2)

您可以尝试/#[a-z0-9]+/i。此模式将替换#后面带空格的任何字母数字字。

preg_replace('/#[a-z0-9]+/i', '', $content)

答案 1 :(得分:0)

您可以尝试此preg_replace('#.*?(?= |\.|,|!|\?)', '', $string);

它将删除以#开头的所有字符串。