Eric @ EricBess WebHome

Voitot eivät ole ylimielinen, ei menetä nälkäinen, on isku rintaan ja kasvoihin, kuten kaivos 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 Function [polku viimeistely asema]

FixPath Tehtävä: korjata likainen polkuja. PHP polku lajittelu-toiminto.
Esimerkki:

? [Kopioi leikepöydälle] Näytä koodi 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 Likaiset polut: \ n"; 
  = 'C://////////Windows//////System' ; //  C:/System $ Polkuja [] = "C :////////// Windows ////// System"; / / C: / System 
  = 'C:\HTML\javascript\..\examples\colors.html' ; //  C:/HTML/examples/colors.html $ Polkuja [] = "C: \ HTML \ javascript \ .. \ esimerkit \ colors.html"; / / C: / HTML / examples / colors.html 
  = '/root/./wwwroot/scripts/../././webpage' ; //  /root/wwwroot/webpage $ Polkuja [] = "/ root /. / Wwwroot / scripts / .. /. /. / Verkkosivu"; / / / root / Wwwroot / verkkosivun 
  = 'wwwroot/webpage/../index.php?querystring' ; //  wwwroot/index.php?querystring $ Polkuja [] = 'Wwwroot / verkkosivun / .. / index.php? Querystring "; / / Wwwroot / index.php? Querystring 
  = 'http://www.php.net/manual/en/../../downloads' ; //  http://www.php.net/downloads $ Polkuja [] = '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 $ Polkuja [] = 'http://www.php.net/downloads/test/test1/test2//./docs.php "; / / http://www.php.net/docs.php 
  = '../downloads/../docs.php' ; //  ../docs.php $ Polkuja [] = '.. / lataukset / .. / docs.php "; / / .. / docs.php 
  = 'localhost//projetos/../_arquivos/../' ; //   "" $ Polkuja [] = 'localhost / / projetos / .. / _arquivos /../'; / / "" 
  = 'C:/downloads/../../../' ; //  C:/ $ Polkuja [] = "C: / lataus /../../../'; / / C: / 
  = 'downloads/../../../' ; //  ../../ $ Polkuja [] = 'lataa /../../../'; / / ../../ 

  $paths as $path ) foreach ($ polkuja kuin $ polku) 
  ( 
      &quot;" . $path . "&quot;  =  &quot;" .  fixpath ( $path ) . "&quot;" ; echo "\ n" ". $ polku". "=" ". fixpath ($ polku)."; 
  ) 
  ?> 
Huomautus: "/ /" yksi vinoviivoilla ohjautuu takaisin juuri.


Tehtävä:

? [Kopioi leikepöydälle] Lataa 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 = "" ) toiminto fixpath ($ path = "") 
  ( 
      / / Sanity check 
      $path == "" ) { return false ; } if ($ polku == "") (meno-paluu väärä;) 

      / / Muuntaa kaikki "\" to "/", ja pyyhkii tyhjää tilaa alussa ja päättyminen merkkijono 
      trim ( preg_replace ( "/ \\ \\ /" , "/" , ( string ) $path ) ) ; $ Path = TRIM (preg_replace ( "/ \ \ \ \ /", "/" (string) $ polku)); 

      / * Tauot alkuperäinen merkkijono osiin: "root" ja "dir". 
      * "Root" voi olla "C: /" (Windows) "/" (Linux) tai "http://www.something.com/" (URL-osoitteita). Tämä on aloittaa tuotanto merkkijono. 
      * "Dir" voi olla "Windows / System", "root / html / examples /", "includes / luokat / class.validator.php" jne. 
      * / 
      "/^( \\ /| \w : \\ /|(http|ftp)s?: \\ / \\ /[^ \\ /]+ \\ /)?(.*)$/i" , $path , $matches ,  PREG_SET_ORDER ) ; preg_match_all ( "/ ^ (\ \ / | \ w: \ \ / | (http | ftp) s?: \ \ / \ \ / [^ \ \ /] + \ \ /)?(.*)$/ i ", $ Polku, $ otteluissa, PREG_SET_ORDER); 

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

      / / Jos "dir"-osa on yksi tai useampi vinoviivoilla alussa, pyyhkii kaikki. 
      preg_replace ( array ( "/^ \\ /+/" ) , array ( "" ) , $path_dir ) ; $ Path_dir = preg_replace (array ( "/ ^ \ \ / + /"), array ( ""), $ path_dir); 

      / / Breaks "dir"-osa kunkin kauttaviiva 
      explode ( "/" , $path_dir ) ; $ Path_parts = räjähtää ( "/", $ path_dir); 

      / / Luo uuden jono on oikealla tiellä. Jokainen elementti on uusi dir (tai tiedoston päätettä, jos olemassa) järjestyksessä. 
      $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] == ".") 
          ( 
              jatkua; 
          ) 
          $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; 
        	  jatkua; 
           ) 
          $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 -; 
                  jatkua; 
              ) 
          ) 

          $real_path_parts , $path_parts [ $i ] ) ; array_push ($ real_path_parts, $ path_parts [$ i]); 
          $ J + +; 
      ) 
      . implode ( "/" , $real_path_parts ) ; return $ path_root. implode ( "/", $ real_path_parts); 
  ) 
  ?> 
1 Star2 Stars3 Stars4 Stars5 Stars (2 ääntä, keskiarvo: 5 / 5)
Loading ... Ladataan ...
- Pani tyytyväisenä merkille luokitus tämä artikkeli

Satunnainen Posts

Tässä asiakirjassa, että lukijat ovat myös huolissaan seuraavasti:

  • N / A

17 heinäkuu 2008 Tekijä: Eric | luokittelemattomat | trackback? | Ei kommentteja | Email This Post Print This Post | 57 katselua

Lisää Kommentti

Jätä vastaus

Ei kommentteja Piilota kommentoidaksesi