PHP FixPath Funció [ruta funció d'acabat]
FixPath Funció: fixar els camins bruts. PHP camí funció de la classificació.
Exemple:
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) ( "" . $path . "" = "" . fixpath ( $path ) . """ ; echo "\ n" ". $ PATH". "=" ". fixpath ($ PATH)". ""; ) ?> |
Nota: "/ /" un més barres d'aconseguir la regressió de l'arrel.
Funció:
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); ) ?> |
| - Va acollir amb beneplàcit la qualificació per a aquest article |
No donacions en els darrers 180 days.Who fer donació de deixar missatge aquí. Donar Ara.
Aquest és un wordpress plugin Wp-donants. Proporciona una funció de donació intel · ligents per al patrocinador autoleave informació continguda en aquest recipient després del pagament. La gent pot donar i presentar el nom o l'adreça URL o TextLink AD. La informació dels donants més recents es mostren en el núvol. La més d'una persona dona, el més gran del seu vincle be.It 's recolzarà més popular interfície de pagament en el futur. Parpal Només la primera. .. Més
Powered By: WP-donants
Posats a l'atzar | En aquest document, els lectors també estan preocupats pel text següent:
|















































Deixi una resposta