Eric @ EricBess WebHome

Guanya no arrogant, no perdre de fam, no hi ha xoc de pit i la cara, com el meu 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 flagCatalan flagFilipino flagHebrew flagIndonesian flagLatvian flagLithuanian flagSerbian flagSlovak flagSlovenian flagUkrainian flagVietnamese flag
By N2H

PHP FixPath Funció [ruta funció d'acabat]

FixPath Funció: fixar els camins bruts. PHP camí funció de la classificació.
Exemple:

? Veure codi 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 bruts camins: \ n"; 
  = 'C://////////Windows//////System' ; //  C:/System $ Camins [] = 'C :////////// ////// Windows System; / / C: / Sistema d' 
  = 'C:\HTML\javascript\..\examples\colors.html' ; //  C:/HTML/examples/colors.html $ Camins [] = 'C: \ HTML \ JavaScript \ .. \ exemples \ colors.html'; / / C: / HTML / exemples / colors.html 
  = '/root/./wwwroot/scripts/../././webpage' ; //  /root/wwwroot/webpage $ Camins [] = '/ root /. / Wwwroot / scripts / .. /. /. / Pàgina web' / / / root / wwwroot / pàgina web 
  = 'wwwroot/webpage/../index.php?querystring' ; //  wwwroot/index.php?querystring $ Camins [] = 'wwwroot / web / .. / index.php? QueryString'; / / wwwroot / index.php? QueryString 
  = 'http://www.php.net/manual/en/../../downloads' ; //  http://www.php.net/downloads $ Camins [] = '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 $ Camins [] = 'http://www.php.net/downloads/test/test1/test2//./docs.php'; / / http://www.php.net/docs.php 
  = '../downloads/../docs.php' ; //  ../docs.php $ Camins [] = '.. / descàrregues / .. / docs.php'; / / .. / docs.php 
  = 'localhost//projetos/../_arquivos/../' ; //   "" $ Camins [] = 'localhost / / Projectes / .. / _arquivos /../'; / / "" 
  = 'C:/downloads/../../../' ; //  C:/ $ Camins [] = 'C: / descàrregues /../../../'; / / C: / 
  = 'downloads/../../../' ; //  ../../ $ Camins [] = 'descàrregues /../../../'; / / ../../ 

  $paths as $path ) foreach ($ camins com $ PATH) 
  ( 
      &quot;" . $path . "&quot;  =  &quot;" .  fixpath ( $path ) . "&quot;" ; echo "\ n" ". $ PATH". "=" ". fixpath ($ PATH)". ""; 
  ) 
  ?> 
Nota: "/ /" un més barres d'aconseguir la regressió de l'arrel.


Funció:

? Descarregar 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ó fixpath ($ path = "") 
  ( 
      / / Comprovar Sanitat 
      $path == "" ) { return false ; } if ($ camí == "") (return false;) 

      / / Converteix tots els "\" a "/", i esborra els espais en blanc al començament i al final de la cadena 
      trim ( preg_replace ( "/ \\ \\ /" , "/" , ( string ) $path ) ) ; $ Path = trimestre (preg_replace ( "/ \ \ /", "/", (string) $ ruta)); 

      / * Escapades de la cadena original en parts: "root" i "dir". 
      * "Arrel" pot ser "C: /" (Windows), "/" (Linux) o "http://www.something.com/" (URL). Aquest serà l'inici de la cadena de producció. 
      * "Dir" pot ser "Windows / System", "root / html / exemples /", "includes / classes / class.validator.php", etc 
      * / 
      "/^( \\ /| \w : \\ /|(http|ftp)s?: \\ / \\ /[^ \\ /]+ \\ /)?(.*)$/i" , $path , $matches ,  PREG_SET_ORDER ) ; preg_match_all ( "/ ^ (\ \ / | \ w: \ \ / | (http | ftp) s?: \ \ / \ \ / [^ \ \ /] + \ \ /)?(.*)$/ i ", $ PATH, $ coincidències, PREG_SET_ORDER); 

      $matches [ 0 ] [ 1 ] ; Path_root $ = $ coincidències [0] [1]; 
      $matches [ 0 ] [ 3 ] ; Path_dir $ = $ coincidències [0] [3]; 

      / / Si "dir" part té una o més barres al principi, esborra tots. 
      preg_replace ( array ( "/^ \\ /+/" ) , array ( "" ) , $path_dir ) ; $ Path_dir = preg_replace (array ( "/ ^ \ \ / + /"), array ( ""), $ path_dir); 

      / / Escapades de "dir" part a cada barra 
      explode ( "/" , $path_dir ) ; $ Path_parts explotar = ( "/", $ path_dir); 

      / / Crea un nou array amb el camí correcte. Cada element és un nou directori (o arxiu en què acaba, si existeix) en seqüència. 
      $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ó ( "/", $ real_path_parts); 
  ) 
  ?> 
1 Star2 Stars3 Stars4 Stars5 Stars (2 vots, mitjana: 5 de 5)
Loading ... Carregant ...
- Va acollir amb beneplàcit la qualificació per a aquest article

Posats a l'atzar

En aquest document, els lectors també estan preocupats pel text següent:

  • N / A

17 de juliol, 2008 Autor: Eric | sense classificar | Trackback | No hi ha comentaris | Email This Post Print This Post | 58 visites

Afegeix un comentari

Deixi una resposta

amagar enviar comentaris