parse_str () parse_url () PHP function

parse_str (string, array)     the query string into associative array

Parameter Description string Required. Specifies the string to be parsed.

Optional array. It specifies the name of the array of memory variables. This parameter indicates the variable will be stored in the array.

Examples

<?php

    $str = "first=value&arr[]=foobar&arr[]=baz";
parse_str($str);
echo $first."<br />";
echo $arr[0]."<br />";
echo $arr[1]."<br />";
parse_str($str,$output);
echo $output['first']."<br />";
echo $output['arr'][0]."<br />";
echo $output['arr'][1]."<br />";


parse_url (string, $ component = 1 ) parsing URL, and return its components, the function parses a URL and returns an associative array that contains the various components present in the URL.
string Required. Provisions url string to be parsed.
option optional parameter, PHP_URL_SCHEME, PHP_URL_HOST, PHP_URL_PORT, PHP_URL_USERor PHP_URL_FRAGMENT to get one of the string section of the URL specified
If no option, parse_url returns an associative array, the array may have key is:
Host
Port
the User
Pass
route path // file
query - after the question mark in the parameter // file?
the fragment - after the hash symbol #

Examples

<?php
$url = "http://www.baidu.com/path?arg=value#anchor";
print_r(parse_url($url));
echo parse_url($url,PHP_URL_PATH);

Guess you like

Origin www.cnblogs.com/rjbc/p/11407741.html