0

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
5
  • 2
    echo str_replace("@","",$mention_url); Commented Dec 11, 2016 at 7:33
  • Str_replace('/@', '/', $url);. $url should include $mention_url and user name ($srting) Commented Dec 11, 2016 at 7:34
  • i try with str_replace not work Commented Dec 11, 2016 at 7:34
  • How are you tryng? str_replace does not modify the original string. $your_string = 'some string' $another_string = str_replace('o', 'a', $your_string); $your_string is still 'some string', whereas $another_string is 'same string' Commented Dec 11, 2016 at 12:49
  • See ideone.com/89Ukav Commented Dec 11, 2016 at 13:52

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

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

1 Comment

Please expand your answer to explain how it answers the question. Code dump answers are not preferred.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.