Ericas @ EricBess WebHome

Galvojate aklai be veiksmą, jis bus žinant tampa bereikšmis

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 Pareigos [kelias apdailos funkciją]

FixPath Pareigos: nustatyti užterštas takai. PHP kelio apdailos funkcija.
Pavyzdys:

 1 
 2 
 3 
 4 
 5 
 6 
 7 
 8 
 9 
 10 
 11 
 12 
 13 
 14 
 15 
 16 
 17 
 18 
  <? Php 
  ; echo "NNN Dirty keliai: n"; 
  = 'C://////////Windows//////System' ; //  C:/System $ Kelius [] = "C :////////// Windows ////// sistema '; / / C: / Sistemos 
  = 'C:HTMLjavascript..examplescolors.html' ; //  C:/HTML/examples/colors.html $ Kelius [] = "C: HTMLjavascript .. examplescolors.html '; / / C: / html / examples / colors.html 
  = '/root/./wwwroot/scripts/../././webpage' ; //  /root/wwwroot/webpage $ Kelius [] = '/ root /. / Wwwroot / scripts / .. /. /. / Tinklalapį "; / / / root / wwwroot / tinklalapį 
  = 'wwwroot/webpage/../index.php?querystring' ; //  wwwroot/index.php?querystring $ Kelius [] = 'wwwroot / tinklalapių / .. / index.php? Užklausos'; / / wwwroot / index.php? Užklausos 
  = 'http://www.php.net/manual/en/../../downloads' ; //  http://www.php.net/downloads $ Kelius [] = '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 $ Kelius [] = 'http://www.php.net/downloads/test/test1/test2//./docs.php'; / / http://www.php.net/docs.php 
  = '../downloads/../docs.php' ; //  ../docs.php $ Kelius [] = '.. / downloads / .. / docs.php'; / / .. / docs.php 
  = 'localhost//projetos/../_arquivos/../' ; //   "" $ Kelius [] = "localhost / / projetos / .. / _arquivos /../'; / /" 
  = 'C:/downloads/../../../' ; //  C:/ $ Kelius [] = "C: / kreipimusi /../../../'; / / C: / 
  = 'downloads/../../../' ; //  ../../ $ Kelius [] = 'parsisiųsti /../../../'; / / ../../ 

  $paths as $path ) foreach ($ keliai kaip $ path) 
  ( 
      . $path . "&quot;  =  &quot;" .  fixpath ( $path ) . "&quot;" ; echo "n". "$ kelią". "=" ". fixpath ($ path)."; 
  ) 
  ?> 
Pastaba: "/ /" vienas nerijos ribos bus atgal šaknis.


Pareigos:

? Atsisiųsti 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 = "" ) funkcija fixpath ($ path = "") 
  ( 
      / / Sanity patikrinti 
      $path == "" ) { return false ; } if ($ path == "") (return false;) 

      / / Pakeičia visus "į" / "ir ištrinti tuščių tarpų pradžioje ir pasibaigus Styga 
      trim ( preg_replace ( "/\/" , "/" , ( string ) $path ) ) ; $ Path = apdaila (preg_replace ( "/ \ /", "/" (string) $ path)); 

      / * Pertraukos originalo eilutę dalims: "root" ir "reż. 
      * "Root" gali būti "C: /" (Windows) "/" (Linux) arba "http://www.something.com/" (URL). Tai bus pradėti produkcijos eilutę. 
      * "Dir" gali būti "Windows / System", "root / html / examples /" includes / classes / class.validator.php "ir tt 
      * / 
      "/^(/|w:/|(http|ftp)s?://[^/]+/)?(.*)$/i" , $path , $matches ,  PREG_SET_ORDER ) ; preg_match_all ("/^(/| w: | (http | ftp) s ?://[^/]+/)?(.*)$/ i ", $ path, $ rungtynės, PREG_SET_ORDER); 

      $matches [ 0 ] [ 1 ] ; $ Path_root = $ rungtynės [0] [1]; 
      $matches [ 0 ] [ 3 ] ; $ Path_dir = $ rungtynės [0] [3]; 

      / / Jei "reż" dalis turi vieną arba daugiau nerijos ribos pradžioje, bus ištrinti visi. 
      preg_replace ( array ( "/^/+/" ) , array ( "" ) , $path_dir ) ; $ Path_dir = preg_replace (array ("/^/+/"), array ( "") $ path_dir); 

      / / Breaks "reż" dalį apie kiekvieną ukośnikiem 
      explode ( "/" , $path_dir ) ; $ Path_parts = sprogti ( "/", $ path_dir); 

      / / Sukuriamas naujas masyvas su dešinėje kelio. Kiekvienas elementas yra naujas reż (arba failo pabaiga, jei yra) iš eilės. 
      $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] == ""). 
          ( 
              toliau; 
          ) 
          $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; 
        	  toliau; 
           ) 
          $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 -; 
                  toliau; 
              ) 
          ) 

          $real_path_parts , $path_parts [ $i ] ) ; array_push ($ real_path_parts, $ path_parts [$ i]); 
          $ J + +; 
      ) 
      . implode ( "/" , $real_path_parts ) ; return $ path_root. Sprogti ( "/", $ real_path_parts); 
  ) 
  ?> 
1 Star2 Stars3 Stars4 Stars5 Stars (2 balsų, vidurkis: 55)
Loading ... Kraunasi ...
- Sveiki reitingas pagal šį straipsnį

Susijusios Prisijungti

Šiame dokumente, skaitytojai taip pat yra susirūpinęs, kad taip:

  • N / A

Liepa 17, 2008 Autorius: eric | Kodai | Trackback | No Comments »| Email This Post Print This Post | 112 peržiūros

Pridėti komentarą

Palikite atsakymą

nėra komentarus