Introduction to the usage of parse_url() function in php

PHP中文网
Release: 2023-02-28 18:56:01
Original
1210 people have browsed it

This article introduces the usage of parse_url() function in PHP. Friends who need to use parse_url() function can refer to this article.

A useful function parse_url in PHP is particularly convenient for analysis of information capture. An example is as follows:

$url = "http://www.daimajiayuan.com/course/"; $parts = parse_url($url);
Copy after login

Code output:

Array
 (
  [scheme] => http 
  [host] => www.daimajiayuan.com 
  [path] => /course
)
Copy after login

Another example:

<?php 
$url = &#39;http://username:password@hostname/path?arg=value#anchor&#39;; 
print_r(parse_url($url)); 
echo parse_url($url, PHP_URL_PATH); 
?>
Copy after login

Code output:

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

As you can see, it can be easily decomposed into a For each part of the URL, it is easy to extract the specified part, such as and another example:

echo parse_url($url, PHP_URL_PATH);
Copy after login

In the second parameter, set the following parameters:
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.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!