简体   繁体   中英

PHP: Change preg_replace

Hello i try to remove "@" from link how can i do this?

Thanks in advance.

$string = "@username";   
$mention_url = $WebsiteURL. "/". "\\0";
$string = preg_replace("/(?<!\S)@([0-9a-zA-Z_]+)/", "<a href='$mention_url'>\\0</a>", $string);

Defualt link is :

http://localhost/@username

i like this (remove @):

http://localhost/username

Well, you can use this also it is working. I have tested it here-- https://regex101.com/r/jqPsfL/1

$da = "http://localhost/@username";
echo preg_replace("/\/\@(\w+)/","/$1",$da);

I think your default data is

http://localhost/@username

and you want to remove @. So, solution is based on that. If I did not understand your problem. Please can you explain what do you want.

Hope it helps you.

$WebsiteURL = 'http://www.walla.co.il';
$string = "@username";   
$string = preg_replace("/@([0-9a-zA-Z_]+)/", "<a href='$WebsiteURL/$1'>$0</a>", $string);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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