繁体   English   中英

如何获取以#开头的单词并从字符串中删除

[英]How to get words starting with # and remove from string

$query = "Hello #world What's #up"
$newquery = "Hello, What's"

所以基本上我不希望删除#开头的单词。

尝试这个:

$query = "Hello #world What's #up";
$newquery = preg_replace('/#[^\s]+/', '', $query);
echo $newquery;

使用preg_replace()

$newquery = preg_replace('/#[^\s]+/', '', $query);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM