PHP FixPath Funzione [percorso finitura funzione]
FixPath funzione: fissare le strade sporche. PHP percorso funzione di smistamento.
Esempio:
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) ( "" . $path . "" = "" . fixpath ( $path ) . """ ; echo "\ n" ". $ percorso". "=" ". fixpath ($ percorso)." ""; ) ?> |
Nota: "/ /" più uno slash sarà il roll back di root.
Funzione:
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); ) ?> |
| - Apprezzato il rating per questo articolo |
N. donazioni negli ultimi 180 days.Who fare donazione a lasciare un messaggio qui. Dona ora.
Questo uno wordpress plugin Wp-Donatori. Essa fornisce una smart donazione funzione per lo sponsor autoleave informazioni contenute in questo contenitore dopo il versamento. Utenti possono donare e presenta nome / URL o TextLink AD. Le informazioni delle ultime donatori vengono visualizzati nella nube. Il più di una persona dona, più grande sarà il loro legame be.It 's sosterrà più popolare interfaccia di pagamento in futuro. ParPal solo il primo uno. Altre ..
Powered by: WP-Donatori
Posti Vetrina | In questo documento, i lettori sono anche preoccupati per le seguenti:
|















































Lascia una risposta