Path relative path converted to absolute path

Source: Internet
Author: User
Extracts a function from the Gregarius. You can automatically convert a relative path in a Web page to an absolute path.
function Relative_to_absolute ($content, $feed _url) {
Preg_match ('/(HTTP|HTTPS|FTP): \/\//', $feed _url, $protocol);
$server _url = Preg_replace ("/(http|https|ftp|news): \/\//", "", $feed _url);
$server _url = preg_replace ("/\/.*/", "", $server _url);
if ($server _url = = ") {
return $content;
}
if (isset ($protocol [0])) {
$new _content = preg_replace ('/href= ' \//', ' href= '. $protocol [0]. $server _url. ' /', $content);
$new _content = preg_replace ('/src= ' \//', ' src= '. $protocol [0]. $server _url. ' /', $new _content);
} else {
$new _content = $content;
}
return $new _content;
}
?>

The above describes the path relative path to the absolute path, including the content of the path, I hope to be interested in PHP tutorial friends helpful.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.