If this script detects then displays all # tags, how do i change it so it makes them all a hyper link? Basically putting an <a href="#">infront of it and a </a> behind
$str = <<<STR
this is a string
with a #tag and
another #hello one
STR;
$matches = array();
if (preg_match_all('/#([^\s]+)/', $str, $matches)) {
var_dump($matches[1]);
}
You can use back-references, and
preg_replaceto do this.Output:
If you want the
#to be part of the link, simply change the regex to/(#[^\s]+)/.Demo: http://ideone.com/T06HQ