PHP 删除以 # 开头的单词


php remove the word starts with #

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

例如

$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 是#单词。我想删除这些词。

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

请帮助我。谢谢

你可以试试/#[a-z0-9]+/i。此模式将替换任何字母数字单词,后跟 # 为空白。

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

你可以试试这个preg_replace('#.*?(?= |'.|,|!|'?)', '', $string);

它将删除任何以 # 开头的字符串。