【发布时间】:2016-12-11 07:28:31
【问题描述】:
您好,我尝试从链接中删除“@”,我该怎么做?
提前致谢。
$string = "@username";
$mention_url = $WebsiteURL. "/". "\\0";
$string = preg_replace("/(?<!\S)@([0-9a-zA-Z_]+)/", "<a href='$mention_url'>\\0</a>", $string);
默认链接是:
http://localhost/@username
我喜欢这个(删除@):
http://localhost/username
【问题讨论】:
-
echo str_replace("@","",$mention_url); -
Str_replace('/@', '/', $url);。 $url 应该包含 $mention_url 和用户名 ($srting) -
我尝试使用 str_replace 不起作用
-
你还好吗? str_replace 不会修改原始字符串。 $your_string = '一些字符串' $another_string = str_replace('o', 'a', $your_string); $your_string 仍然是“某个字符串”,而 $another_string 是“相同的字符串”
标签: php regex string preg-replace