Relative path to absolute path

Discussion in 'PHP' started by samirkumardas, Jul 15, 2008.

  1. #1
    For my HTML Emailing purpose, I need to convert all relative path (href, src) needs to covert into absolute path. For example, there is an image in html page like <img src='images/edit.png' > of the host http://www.abc.com. I need to covert it into <img src='http://www.abc.com/images/edit.png' >.


    Any php script or your help is much appreciated.
     
    samirkumardas, Jul 15, 2008 IP
  2. BDazzler

    BDazzler Peon

    Messages:
    215
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try something like this this:


    $self = $_SERVER['PHP_SELF'];

    $base_path = "http://".$_SERVER['HTTP_HOST']. $self;

    $full_path = $base_path . '/' . $rel_path;



    That may not be exactly what you want, but it should be close
     
    BDazzler, Jul 15, 2008 IP
  3. samirkumardas

    samirkumardas Banned

    Messages:
    123
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi
    Actually I want to replace all href and src at a time. That means I want bulk replace and images location may in different relative path.

    $file=file_get_contents("http:/abc.com");

    Now I want to replace all href and src by absolute path if they are in relative path.

    Thanks
     
    samirkumardas, Jul 15, 2008 IP
  4. BDazzler

    BDazzler Peon

    Messages:
    215
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You can use strstr to see if the pattern http:// exists.
     
    BDazzler, Jul 15, 2008 IP