ummm.. OK
I'm using windows 2000 advanced server/PHP 4.2.2/Apache 2.0.39(my own build.. nothing fancy just mod_ssl and mod_perl) and I'm running into something very retarded...
I'm using preg_replace links within an html doc (local or remote) and making them reference back to the script (so when you click on a link it is parsed again.. kinda like a psuedo proxy)... my problem is that when more than one link is on a line it will only replace the last link on that line, the rest remain untouched. I know this is confucing as hell, so I will post the important portion of the code here
<?
function process_url($url)
{
$url=stripslashes($url);
global $path;
$pathparts=parse_url($path);
if(eregi("/",$url))
{
return(base64_encode($pathparts{scheme}."://".$pathparts{host}.$url));
}
if(!eregi("http://",$url) && !eregi("ftp://",$url))
{
return(base64_encode($pathparts{scheme}."://".$pathparts{host}."/".$url));
}
else{
return(base64_encode($url));
}
}
if($uepath)
{
$path=base64_encode($uepath);
}
if($path)
{
$path=base64_decode($path);
$fp = fopen ("$path", "r") or die();
while (!feof ($fp))
{
$buffer= fgets($fp, 409600);
$output= preg_replace('/<a(.*)href="([^\"]*)"([^>]*)>/ie',"'<a '.stripslashes('\\1').' href=\"linktrans2.php?path='.process_url('\\2').'\"'.stripslashes('\\3').'>'", $buffer, 1000);
$output= preg_replace('/<frame(.*)src="([^\"]*)"([^>]*)>/ie',"'<FRAME '.stripslashes('\\1').' src=\"linktrans2.php?path='.process_url('\\2').'\"'.stripslashes('\\3').'>'", $output, 1000);
$output= preg_replace('/<img(.*)src="([^\"]*)"([^>]*)>/ie',"'<img '.stripslashes('\\1').' src=\"imgtrans.php?path='.process_url('\\2').'\"'.stripslashes('\\3').'>'", $output, 1000);
echo $output;
}
fclose($fp);
}
else
{
?>
<head>
<title>Linktrans2.php</title>
</head>
<body>
<H1>You must select have a valid path</H1>
<form name="linktrans" method="post" action="linktrans2.php">
Enter a URL:<input type="text" name="uepath"><br>
<input type="submit"name="submit" value="submit">
</form>
</body>
<?
}
?>
You'd notice that I raised the line buffer to be a great size, but the same thing still happens on a small line.. for example:
if a line contained '<a href="/login.bml">login</a><a href="/something.bml">something</a>'
it will come out:
'<a href="/login.bml">login</a><a href="†Ûiÿü0ÂX¯z:.®v¥r‰¿²‰ž¶§¹¥">something</a>'
The first link is untouched. I know it is not being pased through the process_url() because when thet occurs an extra space is places betwee the 'a' and the 'href' (for debug purposes). I tried using a limit of -1 in the preg_replace func and I still got same results.. i incresed it to 1000, same results.... help me I'm stumped!
-mark