Re: Reg Expression

From: Date: Fri, 15 Dec 2000 03:58:54 +0000
Subject: Re: Reg Expression
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-30438@lists.php.net to get a copy of this message
Scott Mebberson wrote: > > Hi guys I have some html text and I am trying to find all instances of '<a > href="*">' and replace it with [link | *] - I also have to be able to get it > back the other way so if someone writes [link | *] I can put it back into > '<a href="*">'. * will could contain a-z, A-Z, 0-9 and/or #. > > The following is the reg ex I am currently trying to use, but it is not > working. - Also, I am not sure how to make it remember the value of * so I > plug it into the new format. Does anybody have any ideas?? > > $content = ereg_replace("<\/a href=\"(.+)\">", "[link]", > $content); // this > is for </a> > Scott,This might get you closer: $pat = "<a href=\"(.+)\">.+</a>"; $link = ereg_replace($pat, "[link| \\1]", $string); preg_replace will probably be faster. If you want you want to parse a page with many links, and be able to recall the original matched portion, take a look at preg_match and preg_match_all. Hey Mark! Note that the back ref works for ereg_replace in this case. *shrug* Mike D.

« previous php.general (#30438) next »