I'm using preg_replace()
as in the following code.
$p = preg_replace('/#[\d\w]+/', '<a href="http://'.$_SERVER['HTTP_HOST'].'/search/term:'.str_replace('#', rawurlencode('%23'), '${1}').'">${1}</a>', $p);
$p will be a string like '(#ben)'
However, nothing is output using $1
. Am I using $1
incorrectly?
Should output this: <h2>Bens (<a href="http://example.com/search/term:#ben">ben</a>) cat</h2>