NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page Need a bit of help (eregi_replace not working)

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 09-11-2006, 11:07 AM THREAD STARTER               #1 (permalink)
Senior Member
 
Barrucadu's Avatar
Join Date: Aug 2005
Location: East Yorkshire, England
Posts: 2,689
Barrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to behold
 




Need a bit of help (eregi_replace not working)


DEMO: http://mikor.clearlyhosted.org/proxy...www.google.com
If you view the source (or hover over the links) the target path hasnt been changed properly... heres the code:
PHP Code:
<?php

$page 
$_GET['p'];
$ext substr(strrchr($url"."), 1);
$contents file_get_contents($page);

$exts['html'] = array("htm","html","shtml","php","php3","php4","php5","phtml");
$exts['application'] = array("zip","rar","ext");
$exts['image'] = array("bmp","jpg","jpeg","gif","png","jp2");
????: NamePros.com http://www.namepros.com/programming/236894-need-bit-help-eregi_replace-not-working.html
$exts['video'] = array("mov","wmv","avi","asf","rm","mpg","mp4","mpeg");
$exts['audio'] = array("mp3","wma","wmp","ogg","midi","mid","aiff");

if(
in_array($ext,$exts['html'])){
    
header("Content-type: text/html");
    
FixHTML($contents);
}elseif(
in_array($ext,$exts['application'])){
    
header("Content-type: application/".$ext);
    
EchoItIt($contents);
}elseif(
in_array($ext,$exts['image'])){
    
header("Content-type: image/".$ext);
    
EchoIt($contents);
}elseif(
in_array($ext,$exts['video'])){
    
header("Content-type: video/".$ext);
    
EchoIt($contents);
}elseif(
in_array($ext,$exts['audio'])){
    
header("Content-type: audio/".$ext);
    
EchoIt($contents);
}else{
    if(
eregi('<html>',$contents)){
        
header("Content-type: text/html");
        
FixHTML($contents);
    }else{
        
header("Content-type: text/plain");
        
EchoIt($contents);
    }
}

function 
FixHTML($text){
    
//Vars
    
$parts parse_url($_GET['p']);
    
$uri $parts['scheme'] . '://' .$parts['host'] . $parts['path'];
????: NamePros.com http://www.namepros.com/showthread.php?t=236894
    
//Absoloute URIs (href)
    
$text2 str_replace('href = "http://','href = "http://mikor.clearlyhosted.org/proxy.php?p=',$text);
    
$text2 str_replace('href= "http://','href = "http://mikor.clearlyhosted.org/proxy.php?p=',$text2);
    
$text2 str_replace('href ="http://','href = "http://mikor.clearlyhosted.org/proxy.php?p=',$text2);
    
$text2 str_replace('href="http://','href = "http://mikor.clearlyhosted.org/proxy.php?p=',$text2);
    
//Relative URIs (href)
    
$text2 str_replace('href = "/','href = "http://mikor.clearlyhosted.org/proxy.php?p='.$uri.'/',$text2);
    
$text2 str_replace('href= "/','href = "http://mikor.clearlyhosted.org/proxy.php?p='.$uri.'/',$text2);
    
$text2 str_replace('href ="/','href = "http://mikor.clearlyhosted.org/proxy.php?p='.$uri.'/',$text2);
    
$text2 str_replace('href="/','href = "http://mikor.clearlyhosted.org/proxy.php?p='.$uri.'/',$text2);
    
//Absoloute URIs (src)
    
$text2 str_replace('src = "http://','src = "http://mikor.clearlyhosted.org/proxy.php?p=',$text);
    
$text2 str_replace('src= "http://','src = "http://mikor.clearlyhosted.org/proxy.php?p=',$text2);
    
$text2 str_replace('src ="http://','src = "http://mikor.clearlyhosted.org/proxy.php?p=',$text2);
    
$text2 str_replace('src="http://','src = "http://mikor.clearlyhosted.org/proxy.php?p=',$text2);
    
//Relative URIs (src)
    
$text2 str_replace('src = "/','src = "http://mikor.clearlyhosted.org/proxy.php?p='.$uri.'/',$text2);
    
$text2 str_replace('src= "/','src = "http://mikor.clearlyhosted.org/proxy.php?p='.$uri.'/',$text2);
    
$text2 str_replace('src ="/','src = "http://mikor.clearlyhosted.org/proxy.php?p='.$uri.'/',$text2);
    
$text2 str_replace('src="/','src = "http://mikor.clearlyhosted.org/proxy.php?p='.$uri,$text2);
    
    echo 
$text2;
}

function 
EchoIt($text){
    echo 
$text;
}
?>
Barrucadu is offline  
Old 09-11-2006, 11:38 AM   #2 (permalink)
Senior Member
 
Eric's Avatar
Join Date: Mar 2005
Posts: 4,948
Eric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatness
 

Member of the Month
MOTM September 2005
Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Animal Rescue Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Baby Health Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse Diabetes Protect Our Planet Multiple Sclerosis Autism Adoption Special Olympics
PHP Code:
<?php

$page 
$_GET['p'] = 'http://www.dnwhois.net';
$ext substr(strrchr($url"."), 1);
$contents file_get_contents($page);

$exts['html'] = array("htm","html","shtml","php","php3","php4","php5","phtml");
$exts['application'] = array("zip","rar","ext");
$exts['image'] = array("bmp","jpg","jpeg","gif","png","jp2");
????: NamePros.com http://www.namepros.com/showthread.php?t=236894
$exts['video'] = array("mov","wmv","avi","asf","rm","mpg","mp4","mpeg");
$exts['audio'] = array("mp3","wma","wmp","ogg","midi","mid","aiff");

if(
in_array($ext$exts['html']))
{
    
header("Content-type: text/html");
    
FixHTML($contents);
}
else if(
in_array($ext$exts['application']))
????: NamePros.com http://www.namepros.com/showthread.php?t=236894
{
    
header("Content-type: application/".$ext);
    
EchoItIt($contents);
}
else if(
in_array($ext$exts['image']))
{
    
header("Content-type: image/".$ext);
    
EchoIt($contents);
}
else if(
in_array($ext$exts['video']))
{
    
header("Content-type: video/".$ext);
    
EchoIt($contents);
}
else if(
in_array($ext$exts['audio']))
{
    
header("Content-type: audio/".$ext);
    
EchoIt($contents);
}
else
{
    if(
eregi('<html>'$contents))
    {
        
header("Content-type: text/html");
        
FixHTML($contents);
    }
    else
    {
        
header("Content-type: text/plain");
        
EchoIt($contents);
    }
}

function 
FixHTML($text)
{
    
//Vars
    
$parts parse_url($_GET['p']);
    
$uri $parts['scheme'] . '://' .$parts['host'] . $parts['path'];

    
//Absoloute URIs (href)
    
$text2 preg_replace('#href(=|\s=|=\s|\s=\s)"http:\/\/#i''href="http://mikor.clearlyhosted.org/proxy.php?p='$text);

    
//Relative URIs (href)
    
$text2 preg_replace('#href(=|\s=|=\s|\s=\s)"(\/|)#i''href="http://mikor.clearlyhosted.org/proxy.php?p=' $uri '/'$text2);

    
//Absoloute URIs (src)
    
$text2 preg_replace('#src(=|\s=|=\s|\s=\s)"http:\/\/#i''src="http://mikor.clearlyhosted.org/proxy.php?p='$text2);

    
//Relative URIs (src)
    
$text2 preg_replace('#src(=|\s=|=\s|\s=\s)"(\/|)#i''src="http://mikor.clearlyhosted.org/proxy.php?p=' $uri '/'$text2);
    echo 
$text2;
}

function 
EchoIt($text)
{
    echo 
$text;
}

?>
Ugly regex, but it works.
Eric is offline  
Old 09-11-2006, 11:41 AM THREAD STARTER               #3 (permalink)
Senior Member
 
Barrucadu's Avatar
Join Date: Aug 2005
Location: East Yorkshire, England
Posts: 2,689
Barrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to behold
 




Can you explain the "#src(=|\s=|=\s|\s=\s)"(\/|)#i", I have no idea what it means, lol
Barrucadu is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Liquid Web Smart Servers  
All times are GMT -7. The time now is 12:45 PM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger