Backend Development

PHP Question - been bugging me for a while :/

Submitted by 0x88, , Thread ID: 198799

Thread Closed
0x88
Active Member
Level:
11
Reputation:
17
Posts:
201
Likes:
37
Credits:
889
23-02-2021, 08:30 PM
This post was last modified: 23-02-2021, 08:30 PM by 0x88
#1
This has been bugging me for a while, the function of it is to allow a user to input an @ to someone's profile, and it hyperlink there.


The user enters their input "@userinput" which will then change to '<a href="userinput"> userinput </a>'.
Any help would be greatly appreciated, my attempts can be seen below.

My attempts.
Code:
preg_match('#(?>\@)(\w*)#', $string, $matches);
foreach($matches as $row){
$string = preg_replace('#(?>\@)(\w*)#', '<a href="'.$row.'"> '. $row . "</a>", $string);
}
Code:
$string = preg_replace('#\@(.*)#', '<b><a href="=$1"=> @$1 </a></b>', $string);

Users browsing this thread: 1 Guest(s)