PHP pathinfo () and Parse_url () function usage and difference

Source: Internet
Author: User

Description
Mixed PathInfo (string $path [, int $options])

PathInfo () returns an associative array containing the information with path. Includes the following array cells: dirname,basename and extension.

You can specify which cells to return through the parameter options. They include: Pathinfo_dirname,pathinfo_basename and Pathinfo_extension. The default is to return all the cells. This function returns a string if all the cells are not required to be obtained.

Example #1 PathInfo () example

The code is as follows Copy Code

<?php
$path _parts = PathInfo ("/www/htdocs/index.html");
echo $path _parts["DirName"]. ” “;
echo $path _parts["basename"]. ” “;
echo $path _parts["extension"]. ” “;
?>

The above routines will output:

/www/htdocs
Index.html
htmlphp parse_url resolves the URL and returns its constituent
Parse_url
(PHP 4, PHP 5)

parse_url-resolves the URL and returns its components

Description
Array Parse_url (string $url) This function resolves a URL and returns an associative array containing the various components that appear in the URL.

This function is not used to verify the legality of a given URL, but to decompose it into the sections listed below. An incomplete URL is also accepted, and Parse_url () tries to parse it as correctly as possible.

Parameters

Url
The URL to resolve

return value
The severely unqualified url,parse_url () may return FALSE and emit e_warning. Otherwise, an associative array is returned, and its components are (at least one):

scheme-such as HTTP
Host
Port
User
Pass
Path
query-At the question mark? After
fragment-After the hash symbol #

Example
Example #1 Parse_url () example

The code is as follows Copy Code

<?php
$url = ' Http://username:password@hostname/path?arg=value#anchor ';

Print_r (Parse_url ($url));
?>

The above routines will output:

Array
(
[Scheme] => http
[Host] => hostname
[User] => username
[Pass] => password
[Path] =>/path
[Query] => arg=value
[Fragment] => anchor
)

Comments
Note:

This function cannot be used for relative URLs.

1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.