@ EricBess Eric WebHome

Vittorie non arrogante, non perdere di fame, non vi è scossa torace e del viso, come il mio 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 Funzione [percorso finitura funzione]

FixPath funzione: fissare le strade sporche. PHP percorso funzione di smistamento.
Esempio:

? [Copia negli appunti] Visualizza codice 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 Dirty percorsi: \ n"; 
  = 'C://////////Windows//////System' ; //  C:/System $ Percorsi [] = 'C :////////// ////// di sistema di Windows'; / / C: / System 
  = 'C:\HTML\javascript\..\examples\colors.html' ; //  C:/HTML/examples/colors.html $ Percorsi [] = 'C: \ HTML \ Javascript \ .. \ esempi \ colors.html'; / / C: / HTML / esempi / colors.html 
  = '/root/./wwwroot/scripts/../././webpage' ; //  /root/wwwroot/webpage $ Percorsi [] = '/ root /. / Wwwroot / scripts / .. /. /. / Pagina web'; / / / radice / Wwwroot / pagina web 
  = 'wwwroot/webpage/../index.php?querystring' ; //  wwwroot/index.php?querystring $ Percorsi [] = 'wwwroot / pagina web / .. / index.php? QueryString'; / / wwwroot / index.php? QueryString 
  = 'http://www.php.net/manual/en/../../downloads' ; //  http://www.php.net/downloads $ Percorsi [] = '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 $ Percorsi [] = 'http://www.php.net/downloads/test/test1/test2//./docs.php'; / / http://www.php.net/docs.php 
  = '../downloads/../docs.php' ; //  ../docs.php $ Percorsi [] = '.. / download / .. / docs.php'; / / .. / docs.php 
  = 'localhost//projetos/../_arquivos/../' ; //   "" $ Percorsi [] = 'hostlocale / / projetos / .. / _arquivos /../'; / / "" 
  = 'C:/downloads/../../../' ; //  C:/ $ Percorsi [] = 'C: / downloads /../../../'; / / C: / 
  = 'downloads/../../../' ; //  ../../ $ Percorsi [] = '/../../../'; downloads / / ../../ 

  $paths as $path ) foreach ($ $ percorsi come percorso) 
  ( 
      &quot;" . $path . "&quot;  =  &quot;" .  fixpath ( $path ) . "&quot;" ; echo "\ n" ". $ percorso". "=" ". fixpath ($ percorso)." ""; 
  ) 
  ?> 
Nota: "/ /" più uno slash sarà il roll back di root.


Funzione:

? [Copia negli appunti] Scarica 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 = "" ) funzione fixpath ($ percorso = "") 
  ( 
      / / Controllare Sanity 
      $path == "" ) { return false ; } if ($ path == "") (return false;) 

      / / Converte tutti i "\" a "/", e cancella spazi vuoti all'inizio e alla fine della stringa 
      trim ( preg_replace ( "/ \\ \\ /" , "/" , ( string ) $path ) ) ; $ Path = trim (preg_replace ( "/ \ \ \ \ /", "/", (string) $ path)); 

      / * Breaks la stringa originale a parti: "root" e "dir". 
      * "Root" può essere "C: /" (Windows), "/" (Linux) o "http://www.something.com/" (URL). Questo sarà l'inizio della stringa di output. 
      * "D" può essere "Windows / System", "root / html / esempi /", "include / classi / class.validator.php", ecc 
      * / 
      "/^( \\ /| \w : \\ /|(http|ftp)s?: \\ / \\ /[^ \\ /]+ \\ /)?(.*)$/i" , $path , $matches ,  PREG_SET_ORDER ) ; preg_match_all ( "/ ^ (\ \ / | \ w: \ \ / | (http | ftp) s?: \ \ / \ \ / [^ \ \ /] + \ \ /)?(.*)$/ i ", $ PATH, $ partite, PREG_SET_ORDER); 

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

      / / Se "dir" è parte di una o più barre all'inizio, cancella tutti. 
      preg_replace ( array ( "/^ \\ /+/" ) , array ( "" ) , $path_dir ) ; $ Path_dir = preg_replace (array ( "/ ^ \ \ / + /"), array ( ""), $ path_dir); 

      / / Breaks "dir" parte su ogni barra 
      explode ( "/" , $path_dir ) ; $ = Path_parts esplodere ( "/", $ path_dir); 

      / / Crea un nuovo array con la strada giusta. Ogni elemento è una nuova directory (o file nel finale, se esiste) in sequenza. 
      $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] == '.') 
          ( 
              continuare; 
          ) 
          $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; 
        	  continuare; 
           ) 
          $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 -; 
                  continuare; 
              ) 
          ) 

          $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 voti, media: 5 su 5)
Loading ... Caricamento in corso ...
- Apprezzato il rating per questo articolo

Posti Vetrina

In questo documento, i lettori sono anche preoccupati per le seguenti:

  • N / D

Luglio 17, 2008 Autore: Eric | non classificati | Trackback? | Nessun commento | Email This Post Print This Post | 60 viste

Aggiungi un commento

Lascia una risposta

nascondere inviare commenti