해외축구중계스포츠중계축구중계EPL중계스포츠무료중계실시간스포츠
{"id":692,"date":"2018-01-16T20:18:42","date_gmt":"2018-01-16T20:18:42","guid":{"rendered":"https:\/\/www.wdb24.com\/?p=692"},"modified":"2018-04-22T20:21:29","modified_gmt":"2018-04-22T20:21:29","slug":"10-php-url-functions-every-beginner-must-check","status":"publish","type":"post","link":"https:\/\/www.wdb24.com\/10-php-url-functions-every-beginner-must-check\/","title":{"rendered":"10 PHP Url Functions – Every beginner must check"},"content":{"rendered":"

URL (Uniform Resource Locator) often termed as web address is a unique reference of web resource that is accessible on the internet.To visit any website user go to the browser (chrome, firefox, safari) and type any website name like wdb24.com<\/a> and browser loads requested website.But URLs are not restricted with http\/https. URLs are also used in ftp (file transfer protocol), email (mailto), database access and many other applications.A typical URL look something like this.<\/p>\n

If you want read more about URL then visit https:\/\/en.wikipedia.org\/wiki\/URL<\/a><\/p>\n

In PHP<\/a>, there are bundle of functions which handle URL and its fragments quite well. So in this post, I am going to show you 10 PHP built in functions and their use.<\/p>\n

PHP Built in URL Functions:<\/h2>\n

1) parse_url():<\/h3>\n

This function parses the url and return its components. It is a very handy function and use frequently in php projects.<\/p>\n

Syntax: parse_url(string<\/span> $url, optional<\/span> $component)<\/strong><\/h4>\n\n\n\n
$url<\/span><\/td>\nURL to parse<\/td>\n<\/tr>\n
$component<\/span><\/td>\nSpecify any Component otherwise blank will return an array. Components are PHP_URL_SCHEME, PHP_URL_HOST, PHP_URL_PORT, PHP_URL_USER, PHP_URL_PASS, PHP_URL_PATH, PHP_URL_QUERY or PHP_URL_FRAGMENT<\/td>\n<\/tr>\n<\/table>\n

parse_url example 1:<\/h4>\n
\r\n$parseUrl = parse_url(\"http:\/\/www.example.com\");\r\nprint_r($parseUrl);\r\n<\/pre>\n

The output of the above code is below. Parse url split url into 2 indices. First one is scheme which is http and second is a host name which is www.example.com<\/p>\n

Output:<\/h4>\n
\r\nArray\r\n(\r\n    [scheme] =>http\r\n    [host] => www.example.com\r\n)\r\n<\/pre>\n

parse_url example 2:<\/h4>\n
\r\n$parseUrl2 = parse_url(\"http:\/\/www.example.com:8080?name=ahsan&title=developer#hrefID\");\r\nprint_r($parseUrl2);\r\n<\/pre>\n

In the above code, a very long url passed in parse_url function and parse_url split url into different indexes of array.<\/p>\n

Output:<\/h4>\n
\r\nArray\r\n(\r\n    [scheme] =>http\r\n    [host] => www.example.com\r\n    [port] => 8080\r\n    [query] =>name=ahsan&title=developer\r\n    [fragment] =>hrefID\r\n)\r\n\r\n<\/pre>\n

parse_url example 3:<\/h4>\n
\r\n$ftpURL = parse_url('ftp:\/\/user:password@example.com\/pub\/file.txt');\r\nprint_r($ftpURL);\r\n<\/pre>\n

In the above example ftp url with user, password and file path pass in the parse_url and parse_url split ftp url into different indexes.<\/p>\n

Output:<\/h4>\n
\r\nArray\r\n(\r\n    [scheme] =>ftp\r\n    [host] => example.com\r\n    [user] =>user\r\n    [pass] =>password\r\n    [path] => \/pub\/file.txt\r\n)\r\n<\/pre>\n
\n<\/ins>
\n