note 20484 rejected from function.ereg-replace by alindeman

From: Date: Fri, 05 Apr 2002 00:18:53 +0000
Subject: note 20484 rejected from function.ereg-replace by alindeman
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-28642@lists.php.net to get a copy of this message
I was working on a script which works as a fake proxy of sorts. What it does is open a page and then translate all the links to be opened by the same script. It acts as a seemless embeding so the page apperas to be on my server at all times. I had a hard time figuring out the regex for doing such a thing. I figured sharing it here might be a good Idea for saving others a good deal of time. (note: this only works for anchors with the following format <a href="something.com"> it can be adapted to be smarter and figure out all aceptable a tags) $samplehyperlink="<a href=\"http://www.livejournal.com\"> lalala <a href=\"http://reasonmaster.net\">"; $sample=ereg_replace("<a href=\"([^\"]*)\">","\\1",$samplehyperlink); $links=explode(' ', $sample); $output=$samplehyperlink; foreach($links as $linkage) { print "linkpass: $linkage\n current output:$output\n"; if(ereg("<a href=\"($linkage)\">",$output)) { $output=ereg_replace("<a href=\"($linkage)\">","<a href=linktran.php?path=".urlencode($linkage)."\">",$output); } print"output after ereg: $output\n"; } echo $output; If someone can come up with something similar, it's be much appreciated! -Mark

« previous php.notes (#28642) next »