coders.. the ultimate convert relative links to absolute links?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Brujah
    Beer Money Baron
    • Jan 2001
    • 22157

    #1

    coders.. the ultimate convert relative links to absolute links?

    Do you know how? Share a php function.. convert relative links to absolute.
  • geeknik
    l337 h4x0r!#%
    • Feb 2005
    • 8364

    #2
    Try this one:

    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.
    hacker 4 hire.

    Comment

    • Brujah
      Beer Money Baron
      • Jan 2001
      • 22157

      #3
      will test it.

      Comment

      • geeknik
        l337 h4x0r!#%
        • Feb 2005
        • 8364

        #4
        I'll keep looking.
        hacker 4 hire.

        Comment

        • woj
          <&(©¿©)&>
          • Jul 2002
          • 47880

          #5
          Originally posted by geeknik
          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...
          Custom Software Development, email: woj#at#wojfun#.#com to discuss details or skype: wojl2000 or gchat: wojfun or telegram: wojl2000
          Affiliate program tools: Hosted Galleries Manager Banner Manager Video Manager
          Wordpress Affiliate Plugin Pic/Movie of the Day Fansign Generator Zip Manager

          Comment

          • Brujah
            Beer Money Baron
            • Jan 2001
            • 22157

            #6
            Originally posted by woj
            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.

            Comment

            Working...