Total Users Online: 0 üye, 248 guest | Tarih/Saat: 2026-05-25 02:19
 
PHP Script for Converting Relative to Absolute URL
2011-03-25 15:53 GMT  oklu Alnt
Kaan

User is: Online status   Gender_M
Posts: 2772
Ülke: İstanbul - 34
Meslek: Serbest Meslek
Age: 43

PHP Script for Converting Relative to Absolute URL

This is a very simple PHP script to convert relative URL to its absolute path, given a base URL. e.g: converting lena.jpg to http://www.example.com/a/b/ali.jpg.

Kod:
function rel2abs($rel, $base)
{
    /* return if already absolute URL */
    if (parse_url($rel, PHP_URL_SCHEME) != '') return $rel;
    /* queries and anchors */
    if ($rel[0]=='#' || $rel[0]=='?') return $base.$rel;
    /* parse base URL and convert to local variables:
       $scheme, $host, $path */
    extract(parse_url($base));
    /* remove non-directory element from path */
    $path = preg_replace('#/[^/]*$#', '', $path);
    /* destroy path if relative url points to root */
    if ($rel[0] == '/') $path = '';
    /* dirty absolute URL */
    $abs = "$host$path/$rel";
    /* replace '//' or '/./' or '/foo/../' with '/' */
    $re = array('#(/\.?/)#', '#/(?!\.\.)[^/]+/\.\./#');
    for($n=1; $n>0; $abs=preg_replace($re, '/', $abs, -1, $n)) {
    /* absolute URL is ready! */
    return $scheme.'://'.$abs;

}
Konuyla İlgili Diğer Başlıklar
Facebook Style TextArea with Wall Posting Script using jQuery PH
Seditio Hazır Script Yazılım Sitesi
Seditio-eklenti.com/sifre/ - script istek!
Seditio-Eklenti/Yukle Script
Include Script Plugin
Emlak, Oto Galeri, Rent A Car, ?iir, Edebiyat Script Sipari?lerinizi Verebilirsiniz.
Detaylar ??in: kaan@ntka.org

Seditio 170 ?ndir
Capte M?zik ?ndir
Seditio Toolbar ?ndir

 

Powered by Seditio © 2009-2012 All Rights Reserved