Page 1 of 1

PCRE code

Posted: Fri Jun 27, 2008 8:20 am
by barak
Hi,
I have some problems with getting the address from a <A> tag.
I made this little function:

Code: Select all

function href_d($string)
{
preg_replace("#<a[?: href=('|\")((\w:/\.\?\#&=\-)*)\\2]?[\w\"'_\s]*>#iU","1 \\2",$string); 
htmlspecialchars($string);
return  $string;
}
but...
There is some error.
Its retrieving me the same string i entered.
Any one see the problem?
Ty

Re: PCRE code

Posted: Fri Jun 27, 2008 8:56 am
by Stryks
I cant remember ... does preg_replace actually modify the subject string, or just return a modified copy?

Perhaps ...

Code: Select all

$new_string = preg_replace("#<a[?: href=('|\")((\w:/\.\?\#&=\-)*)\\2]?[\w\"'_\s]*>#iU","1 \\2",$string);
return htmlspecialchars($new_string);