GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   coders.. the ultimate convert relative links to absolute links? (https://gfy.com/showthread.php?t=748266)

Brujah 07-03-2007 10:32 AM

coders.. the ultimate convert relative links to absolute links?
 
Do you know how? Share a php function.. convert relative links to absolute.

geeknik 07-03-2007 10:33 AM

Try this one:

Quote:

function absolute_url($txt, $base_url){
$needles = array('href="', 'src="', 'background="');
$new_txt = '';
if(substr($base_url,-1) != '/') $base_url .= '/';
$new_base_url = $base_url;
$base_url_parts = parse_url($base_url);

foreach($needles as $needle){
while($pos = strpos($txt, $needle)){
$pos += strlen($needle);
if(substr($txt,$pos,7) != 'http://' && substr($txt,$pos,8) != 'https://' && substr($txt,$pos,6) != 'ftp://' && substr($txt,$pos,9) != 'mailto://'){
if(substr($txt,$pos,1) == '/') $new_base_url = $base_url_parts['scheme'].'://'.$base_url_parts['host'];
$new_txt .= substr($txt,0,$pos).$new_base_url;
} else {
$new_txt .= substr($txt,0,$pos);
}
$txt = substr($txt,$pos);
}
$txt = $new_txt.$txt;
$new_txt = '';
}
return $txt;
}
$txt is your HTML code where you want to convert your relative links.

Brujah 07-03-2007 10:37 AM

will test it. :)

geeknik 07-03-2007 10:45 AM

I'll keep looking.

woj 07-03-2007 11:27 AM

Quote:

Originally Posted by geeknik (Post 12697209)
Try this one:



$txt is your HTML code where you want to convert your relative links.

substr?! you can do it with probably one line of preg_match_replace....

anyway, if you wanna invest a few bucks, hit me up (icq: 33375924) I can probably cook something up...

Brujah 07-03-2007 11:30 AM

Quote:

Originally Posted by woj (Post 12697620)
substr?! you can do it with probably one line of preg_match_replace....

anyway, if you wanna invest a few bucks, hit me up (icq: 33375924) I can probably cook something up...

was mostly looking for a better function than I was already using. It has to account for the '../../blah.jpg' type links too, etc.. I have it working but it's not "pretty" yet.


All times are GMT -7. The time now is 08:35 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123