Hướng dẫn php parse current url
(PHP 4, PHP 5, PHP 7, PHP 8) parse_url — Parse a URL and return its components Descriptionparse_url(string This function is not meant to validate the given URL, it only breaks it up into the parts listed below. Partial and invalid URLs are also accepted, parse_url() tries its best to parse them correctly. Parametersurl The URL to parse. component Specify one of Return Values On seriously malformed URLs, parse_url() may return If the
If the http://example.com/foo → query = null, fragment = null http://example.com/foo? → query = "", fragment = null http://example.com/foo# → query = null, fragment = "" http://example.com/foo?# → query = "", fragment = "" Previously all cases resulted in query and fragment being Note that control characters (cf. ctype_cntrl()) in the
components are replaced with underscores ( Changelog
ExamplesExample #1 A parse_url() example
The above example will output: array(8) { ["scheme"]=> string(4) "http" ["host"]=> string(8) "hostname" ["port"]=> int(9090) ["user"]=> string(8) "username" ["pass"]=> string(8) "password" ["path"]=> string(5) "/path" ["query"]=> string(9) "arg=value" ["fragment"]=> string(6) "anchor" } string(4) "http" string(8) "username" string(8) "password" string(8) "hostname" int(9090) string(5) "/path" string(9) "arg=value" string(6) "anchor" Example #2 A parse_url() example with missing scheme
The above example will output: array(3) { ["host"]=> string(15) "www.example.com" ["path"]=> string(5) "/path" ["query"]=> string(17) "googleguy=googley" } NotesCaution This function may not give correct results for relative or invalid URLs, and the results may not even match common behavior of HTTP clients. If URLs from untrusted input need to be parsed, extra validation is required, e.g. by using filter_var() with the
See Also
thomas at gielfeldt dot com ¶ 10 years ago
= 'http://usr::81/mypath/myfile.html?a=b&b[]=2&b[]=3#myfragment';
lauris () lauris ! lv ¶ 8 years ago
$parts === false) mys5droid at gmail dot com ¶ 6 years ago
echo relativeToAbsolute($absolute, $absolute) . "\n";
simbappo ¶ 2 years ago
jerome at chaman dot ca ¶ 7 years ago
adrian-php at sixfingeredman dot net ¶ 15 years ago
// Step 7 pjpawel ¶ 5 months ago
vbrazas15 at gmail dot com ¶ 1 year ago
vdklah at hotmail dot com ¶ 13 years ago
to1ne at hotmail dot com ¶ 14 years ago
$out; ivijan dot stefan at gmail dot com ¶ 8 years ago
kibblewhite+php at live dot com ¶ 1 year ago
= 'http://usr::81/mypath/myfile.html?a=b&b[]=2&b[]=3&z=9#myfragment';$new_url_01_overwrite_query_params = parse_rebuild_url( $test_url, array( demerit ¶ 5 years ago
therselman at gmail ¶ 10 years ago
laszlo dot janszky at gmail dot com ¶ 10 years ago
ap dot public1 at gmail dot com ¶ 13 years ago
zappascripts at gmail com ¶ 5 years ago
$url; utilmind ¶ 9 years ago
Rob ¶ 7 years ago
$uri->getUri(); //scheme:child:scheme.VALIDscheme123:usr:/mypath/myfile.html?a=b&b[]=2&b[]=3#myfragment spam at paulisageek dot com ¶ 15 years ago
nirazuelos at gmail dot com ¶ 12 years ago
need_sunny at yahoo dot com ¶ 12 years ago
$var as $val) jesse at example dot com ¶ 12 years ago
bramg dot net1 at gmail dot com ¶ 4 years ago
404 ( '404_not_found_message' ); ?>
solenoid at example dot com ¶ 12 years ago
admin at griefer1999 dot uhostfull dot com ¶ 7 years ago
xellisx ¶ 13 years ago
$var as $val)
boctulus @ gmail co!m ¶ 2 years ago
Anonymous ¶ 4 years ago
Anonymous ¶ 4 years ago
Anonymous ¶ 4 years ago
$params; RobertVow ¶ 11 months ago
|