I’ve recently been working with a simple Twitter API for PHP and came across this code to make @username be linked with twitter.com/username. Unfortunately this code creates it so @username links to http://twitter.com/@username, resulting in error. There are many parts to this code I do not understand, such as ^\v and others (seen below). Can anyone give me an explanation of what they signify?
$ret = preg_replace('/(^|[^\w])(@[\d\w\-]+)/', '\\1<a href="http://twitter.com/$2">$2</a>' ,$ret);
Easy one:
The only difference is the @ was moved out of the capturing group, which means it has to be manually added to the output within the link.
Also, \w includes digits so the \d is superfluous. So you could simply it to: