php - URL dissector that splits up a query string -
ok reading through piece of source code , not understand purpose of specific area.
class url_processor { private static $urlpath; private static $urlbits = array(); /* gets data current url @return void */ public function geturldata() { $urldata = (isset($_get['page'])) ? $_get['page'] : '' ; self::$urlpath = $urldata; if( $urldata == '' ) { self::$urlbits[] = 'home'; self::$urlpath = 'home'; } else { $data = explode( '/', $urldata ); while ( !empty( $data ) && strlen( reset( $data ) ) === 0 ) { array_shift( $data ); } while ( !empty( $data ) && strlen( end( $data ) ) === 0) { array_pop($data); } self::$urlbits = $this->array_trim( $data ); } } private function array_trim( $array ) { while ( ! empty( $array ) && strlen( reset( $array ) ) === 0) { array_shift( $array ); } while ( !empty( $array ) && strlen( end( $array ) ) === 0) { array_pop( $array ); } return $array; } }
so understanding 2 while loops 'array_shift' in geturldata method empty out array according logic second while loop wont able empty out because first while loop did.
then last line of method geturldata
self::$urlbits = $this->array_trim( $data );
does same thing how if passed in argument empty already?
very confused!!!
the first while loop removes leading elements in array string length zero, second 1 same trailing elements. reset($array) point first, end($array) last element.
why mushes through second time? don't know.
Comments
Post a Comment