PCRE code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
barak
Forum Newbie
Posts: 2
Joined: Tue May 20, 2008 6:25 am

PCRE code

Post 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
User avatar
Stryks
Forum Regular
Posts: 746
Joined: Wed Jan 14, 2004 5:06 pm

Re: PCRE code

Post 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);
 
Post Reply