检测哈希标记并删除#以获取干净的url

问题描述 投票:0回答:1

考虑字符串:

$tring = 'e.g. i want to #sleep.';

能够使用以下方法检查哈希标签

echo preg_replace('/(#\w+)/', '\1', $tring);

我想做的是发送不带哈希的标签,即sleep而不是#sleep

php regex preg-replace preg-match hashtag
1个回答
0
投票

我认为您想要:

echo preg_replace('/#/', '', $tring);

OR

echo preg_replace('/.+?#(.+?)/', '\1', $tring);
© www.soinside.com 2019 - 2024. All rights reserved.