php - How to Parse array elements of an url -
i have url looks this:
http://localhost/projectcode12may2014/ampanel/index.php?rel=common_listing&module=company&field%5b%5d=address&adv_operation%5b%5d=c&value%5b%5d=sector&query_type%5b%5d=and&submit=submit in decoded form, looks like:
http://localhost/projectcode12may2014/ampanel/index.php?rel=common_listing&module=company&field[]=address&adv_operation[]=c&value[]=sector&query_type[]=and&submit=submit i trying parse url , values of field[], adv_operation[] , query_type[] arrays, getting array written in text if seek parse these fields. using parse_url() , parse_str() parsing. can suggest suitable method this? in advance.
you're displaying array section incorrectly, because method should work.
you utilize parse_url extract "query" segment of url, utilize parse_str load variable.
example:
$url = "http://example.com/page.php?a=apple&b=banana&z=zebra&arr[]=1&arr[]=2"; $query = parse_url($url, php_url_query); var_dump($query); // string(40) "a=apple&b=banana&z=zebra&arr[]=1&arr[]=2" parse_str($query, $parsed); var_dump($parsed); /* array(4) { ["a"]=> string(5) "apple" ["b"]=> string(6) "banana" ["z"]=> string(5) "zebra" ["arr"]=> array(2) { [0]=> string(1) "1" [1]=> string(1) "2" } } */ // $parsed["arr"] array(1, 2); php html arrays
No comments:
Post a Comment