Visualizzazione dei risultati da 1 a 5 su 5
  1. #1
    Utente bannato
    Registrato dal
    Jan 2009
    Messaggi
    186

    ignoranza abissale, come si usa questa funzione

    Se non ho capito male dovrebbe restituire la base dato un indirizzo internet, però come cavolo si usa ? se faccio resolve_url($url) mi pare non funzioni.

    Codice PHP:
    function resolve_url($base$url) {         if (!strlen($base)) return $url;         // Step 2         if (!strlen($url)) return $base;         // Step 3         if (preg_match('!^[a-z]+:!i', $url)) return $url;         $base = parse_url($base);         if ($url{0} == "#") {                 // Step 2 (fragment)                 $base['fragment'] = substr($url, 1);                 return unparse_url($base);         }         unset($base['fragment']);         unset($base['query']);         if (substr($url, 0, 2) == "//") {                 // Step 4                 return unparse_url(array(                         'scheme'=>$base['scheme'],                         'path'=>$url,                 ));         } else if ($url{0} == "/") {                 // Step 5                 $base['path'] = $url;         } else {                 // Step 6                 $path = explode('/', $base['path']);                 $url_path = explode('/', $url);                 // Step 6a: drop file from base                 array_pop($path);                 // Step 6b, 6c, 6e: append url while removing "." and ".." from                 // the directory portion                 $end = array_pop($url_path);                 foreach ($url_path as $segment) {                         if ($segment == '.') {                                 // skip                         } else if ($segment == '..' && $path && $path[sizeof($path)-1] != '..') {                                 array_pop($path);                         } else {                                 $path[] = $segment;                         }                 }                 // Step 6d, 6f: remove "." and ".." from file portion                 if ($end == '.') {                         $path[] = '';                 } else if ($end == '..' && $path && $path[sizeof($path)-1] != '..') {                         $path[sizeof($path)-1] = '';                 } else {                         $path[] = $end;                 }                 // Step 6h                 $base['path'] = join('/', $path);          }         // Step 7         return unparse_url($base); 

  2. #2
    Utente di HTML.it L'avatar di dottwatson
    Registrato dal
    Feb 2007
    Messaggi
    3,012
    perfavore posta la funzione NON su una sola riga...
    Non sempre essere l'ultimo è un male... almeno non devi guardarti le spalle

    il mio profilo su PHPClasses e il mio blog laboweb

  3. #3
    Utente bannato
    Registrato dal
    Jan 2009
    Messaggi
    186
    Originariamente inviato da dottwatson
    perfavore posta la funzione NON su una sola riga...
    e come si fa ?

  4. #4
    E' questo forum che e' fatto male: NON usare i pulsanti, scrivi a mano [ PHP ] e [ /PHP ] (senza gli spazi) e il codice in mezzo a questi due pseudo-tag.

  5. #5
    C'ho provato io....


    Codice PHP:
    function resolve_url($base$url) {         
    if (!
    strlen($base)) 
        return 
    $url;         // Step 2        
    if (!strlen($url)) 
       return 
    $base;         // Step 3         
    if (preg_match('!^[a-z]+:!i'$url)) 
       return 
    $url;         
    $base parse_url($base);        
     if (
    $url{0} == "#") {                 
    // Step 2 (fragment)                 
       
    $base['fragment'] = substr($url1);                 
          return 
    unparse_url($base);         
    }         
    unset(
    $base['fragment']);        
    unset(
    $base['query']);         
    if (
    substr($url02) == "//") {                 
    // Step 4                 
       
    return unparse_url(array('scheme'=>$base['scheme'],'path'=>$url,));         

    else if (
    $url{0} == "/") {                 
    // Step 5                 
    $base['path'] = $url;         

    else {                 
    // Step 6                 
    $path explode('/'$base['path']);                 
    $url_path explode('/'$url);                 
    // Step 6a: drop file from base                 
    array_pop($path);                
     
    // Step 6b, 6c, 6e: append url while removing "." and ".." from                 
    // the directory portion                 
    $end array_pop($url_path);                 
    foreach (
    $url_path as $segment) {                         
       if (
    $segment == '.') {                                 
          
    // skip                         
       

       else if (
    $segment == '..' && $path && $path[sizeof($path)-1] != '..'){                            
         
    array_pop($path);                         
       } 
       else {                                 
       
    $path[] = $segment;                         
       }                 
    }                 
    // Step 6d, 6f: remove "." and ".." from file portion                 
    if ($end == '.') {                         
       
    $path[] = '';                 

    else if (
    $end == '..' && $path && $path[sizeof($path)-1] != '..') {                         
       
    $path[sizeof($path)-1] = '';                 

    else {                         
       
    $path[] = $end;                 
    }                 
    // Step 6h                 
    $base['path'] = join('/'$path);          
    }         
    // Step 7        
     
    return unparse_url($base); 

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.