What regular expression should I use to detect is the text I want to hyperlink had been already hyperlinked.
Example:
I use
$text = preg_replace('/((http)+(s)?:\/\/[^<>\s]+)/i', '<a href="\\0">\\0</a>', $text);
to link regular URL, and
$text = preg_replace('/[@]+([A-Za-z_0-9]+)/', '@<a href="http://twitter.com/#!/\\1">\\1</a>', $text);
to link Twitter handle.
I want to detect whether or not the text I’m going to hyperlink had been wrapped in <a href=""></a> already.
Simple, replace the regular URLs first, as it won’t affect anything starting with an
@cause no URL starts with an@. Then replace the twitter handles.That way you don’t need to detect if it’s been hyperlinked already.