note 20484 added to function.ereg-replace
| From: | turrets at hotmail dot com | Date: | Thu, 04 Apr 2002 23:41:51 +0000 |
| Subject: | note 20484 added to function.ereg-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-28641@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
--
http://www.php.net/manual/en/function.ereg-replace.php
http://master.php.net/manage/user-notes.php?action=edit+20484
http://master.php.net/manage/user-notes.php?action=delete+20484
http://master.php.net/manage/user-notes.php?action=reject+20484