Eric @ EricBess WebHome

Gana no arrogante, no perder de hambre, no hay choque de pecho y la cara, como el mío Pinghu

Chinese (Simplified) flagItalian flagKorean flagPortuguese flagEnglish flagGerman flagFrench flagSpanish flagJapanese flagArabic flagRussian flagGreek flagDutch flagBulgarian flagCzech flagCroat flagDanish flagFinnish flagHindi flagPolish flagRumanian flagSwedish flagNorwegian flag
By N2H

PHP FixPath Función [ruta función de acabado]

FixPath Función: fijar los caminos sucios. PHP camino función de la clasificación.
Ejemplo:

? [Copiar al portapapeles] Ver código PHP
 1 
 2 
 3 
 4 
 5 
 6 
 7 
 8 
 9 
 10 
 11 
 12 
 13 
 14 
 15 
 16 
 17 
 18 
  <? Php 
      Dirty paths: \n " ; echo "\ n \ n \ n sucios caminos: \ n"; 
  = 'C://////////Windows//////System' ; //  C:/System $ Caminos [] = 'C :////////// ////// Windows System; / / C: / Sistema de 
  = 'C:\HTML\javascript\..\examples\colors.html' ; //  C:/HTML/examples/colors.html $ Caminos [] = 'C: \ HTML \ JavaScript \ .. \ ejemplos \ colors.html'; / / C: / HTML / ejemplos / colors.html 
  = '/root/./wwwroot/scripts/../././webpage' ; //  /root/wwwroot/webpage $ Caminos [] = '/ root /. / Wwwroot / scripts / .. /. /. / Página web' / / / root / wwwroot / página web 
  = 'wwwroot/webpage/../index.php?querystring' ; //  wwwroot/index.php?querystring $ Caminos [] = 'wwwroot / web / .. / index.php? QueryString'; / / wwwroot / index.php? QueryString 
  = 'http://www.php.net/manual/en/../../downloads' ; //  http://www.php.net/downloads $ Caminos [] = 'http://www.php.net/manual/en/../../downloads'; / / http://www.php.net/downloads 
  = 'http://www.php.net/downloads/test/test1/test2//./docs.php' ; //  http://www.php.net/docs.php $ Caminos [] = 'http://www.php.net/downloads/test/test1/test2//./docs.php'; / / http://www.php.net/docs.php 
  = '../downloads/../docs.php' ; //  ../docs.php $ Caminos [] = '.. / descargas / .. / docs.php'; / / .. / docs.php 
  = 'localhost//projetos/../_arquivos/../' ; //   "" $ Caminos [] = 'localhost / / Proyectos / .. / _arquivos /../'; / / "" 
  = 'C:/downloads/../../../' ; //  C:/ $ Caminos [] = 'C: / descargas /../../../'; / / C: / 
  = 'downloads/../../../' ; //  ../../ $ Caminos [] = 'descargas /../../../'; / / ../../ 

  $paths as $path ) foreach ($ caminos como $ PATH) 
  ( 
      &quot;" . $path . "&quot;  =  &quot;" .  fixpath ( $path ) . "&quot;" ; echo "\ n" ". $ PATH". "=" ". fixpath ($ PATH)". ""; 
  ) 
  ?> 
Nota: "/ /" uno más barras de lograr la regresión de la raíz.


Función:

? [Copiar al portapapeles] Descarga fixpath.php
 1 
 2 
 3 
 4 
 5 
 6 
 7 
 8 
 9 
 10 
 11 
 12 
 13 
 14 
 15 
 16 
 17 
 18 
 19 
 20 
 21 
 22 
 23 
 24 
 25 
 26 
 27 
 28 
 29 
 30 
 31 
 32 
 33 
 34 
 35 
 36 
 37 
 38 
 39 
 40 
 41 
 42 
 43 
 44 
 45 
 46 
 47 
 48 
 49 
 50 
 51 
 52 
 53 
  <? Php 
  $path = "" ) función fixpath ($ path = "") 
  ( 
      / / Comprobar Sanidad 
      $path == "" ) { return false ; } if ($ camino == "") (return false;) 

      / / Convierte todos los "\" a "/", y borra los espacios en blanco al principio y al final de la cadena 
      trim ( preg_replace ( "/ \\ \\ /" , "/" , ( string ) $path ) ) ; $ Path = TRIM (preg_replace ( "/ \ \ \ \ \ \ /", "/", (string) $ ruta)); 

      / * Escapadas de la cadena original en partes: "root" y "dir". 
      * "Raíz" puede ser "C: /" (Windows), "/" (Linux) o "http://www.something.com/" (URL). Este será el inicio de la cadena de producción. 
      * "Dir" puede ser "Windows / System", "root / html / ejemplos /", "includes / clases / class.validator.php", etc 
      * / 
      "/^( \\ /| \w : \\ /|(http|ftp)s?: \\ / \\ /[^ \\ /]  \\ /)?(.*)$/i" , $path , $matches ,  PREG_SET_ORDER ) ; preg_match_all ( "/ ^ (\ \ / | \ w: \ \ / | (http | ftp) s?: \ \ / \ \ / [^ \ \ /]   \ \ /)?(.*)$/ i ", $ PATH, $ coincidencias, PREG_SET_ORDER); 

      $matches [ 0 ] [ 1 ] ; Path_root $ = $ coincidencias [0] [1]; 
      $matches [ 0 ] [ 3 ] ; Path_dir $ = $ coincidencias [0] [3]; 

      / / Si "dir" parte tiene una o más barras al principio, borra todos. 
      preg_replace ( array ( "/^ \\ / /" ) , array ( "" ) , $path_dir ) ; $ Path_dir = preg_replace (array ( "/ ^ \ \ /   /"), array ( ""), $ path_dir); 

      / / Escapadas de "dir" parte en cada barra 
      explode ( "/" , $path_dir ) ; $ Path_parts explotar = ( "/", $ path_dir); 

      / / Crea un nuevo array con el camino correcto. Cada elemento es un nuevo directorio (o archivo en el que termina, si existe) en secuencia. 
      $i = $j = 0 , $real_path_parts = array ( ) ; $i < count ( $path_parts ) ; $i    ) for ($ i = $ j = 0, $ real_path_parts = array (); $ i <count ($ path_parts); $ i    ) 
      ( 
          $path_parts [ $i ] == '.' ) if ($ path_parts [$ i] == ''). 
          ( 
              continuar; 
          ) 
          $path_parts [ $i ] == '' ) && ( $i != ( count ( $path_parts ) - 1 ) ) ) else if (($ path_parts [$ i] =='') & & ($ i! = (count ($ path_parts) - 1))) 
          ( 
        	  array ( ) ; $ Real_path_parts = array (); 
        	  0 ; $ J = 0; 
        	  continuar; 
           ) 
          $path_parts [ $i ] == '..' ) else if ($ path_parts [$ i] =='..') 
          ( 
              isset ( $real_path_parts [ $j - 1 ] ) && $real_path_parts [ $j - 1 ] != '..' )   || ( $path_root != "" ) ) if ((isset ($ real_path_parts [$ j - 1]) & & $ real_path_parts [$ j - 1]!'..') = | | ($ path_root! = "")) 
              ( 
                  $real_path_parts ) ; array_pop ($ real_path_parts); 
                  $ J -; 
                  continuar; 
              ) 
          ) 

          $real_path_parts , $path_parts [ $i ] ) ; array_push ($ real_path_parts, $ path_parts [$ i]); 
          $ J    ; 
      ) 
      . implode ( "/" , $real_path_parts ) ; return $ path_root. implosión ( "/", $ real_path_parts); 
  ) 
  ?> 
1 Star2 Stars3 Stars4 Stars5 Stars (2 votos, promedio: 5 de 5)
Loading ... Cargando ...
- Acogió con beneplácito la calificación para este artículo

Puestos al azar

En este documento, los lectores también están preocupados por el texto siguiente:

  • N / A

17 de julio, 2008 Autor: Eric | sin clasificar | Trackback | No hay comentarios | Email This Post Print This Post | 51 visitas

Añadir un comentario

Deje una respuesta

No hay comentarios ocultar enviar comentarios