Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use parse_url in php to parse URL and return its components

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article is about how to use parse_url to parse URL to return its components in php. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Parse_url

(PHP 4, PHP 5)

Parse_url-parses the URL and returns its components

Description

Array parse_url (string $url)

This function parses a URL and returns an associative array containing the various components that appear in the URL.

This function is not used to verify the validity of a given URL, but to decompose it into the parts listed below. Incomplete URL is also accepted, and parse_url () will try to parse it as correctly as possible.

Parameters.

Url

URL to be parsed

Return value

For seriously unqualified URL,parse_url (), it may return FALSE and issue E_WARNING. Otherwise, an associative array is returned with at least one component:

Scheme-such as http

Host

Port

User

Pass

Path

Query-in the question mark? After that

Fragment-after the hash symbol #

Example

Example 2369. Parse_url () example

The above example outputs:

Array ([scheme] = > http [host] = > hostname [user] = > username [pass] = > password [path] = > / path [query] = > arg=value [fragment] = > anchor)

Annotation

Note: this function cannot be used for relative URL.

Note: parse_url () is specifically used to parse URL rather than URI. However, to comply with the need for PHP backward compatibility, three slashes (file:///...) are allowed for the file:// protocol. No other agreement can do that.

Thank you for reading! This is the end of this article on "how to use parse_url to parse URL to return its components in php". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report