Introduction to URL Functions in PHP and examples of using example _php

Source: Internet
Author: User
Tags urlencode
base64_encode-encoding data using MIME base64
Base64_encode () returns uses Base64 to encode data. This encoding is designed so that binary data can be transmitted through a non-pure 8-bit transport layer, such as the body of an e-mail message.
base64-encoded data takes up about 33% more space than the original data.

Copy the Code code as follows:
$str = ' This was an encoded string ';
vghpcybpcybhbiblbmnvzgvkihn0cmluzw==
echo Base64_encode ($STR);
?>

base64_decode-decoding data encoded with MIME base64
Base64_decode () Decodes the Encoded_data, returns the original data, and returns FALSE if it fails. The returned data may be binary.

Copy the Code code as follows:
$str = ' vghpcybpcybhbiblbmnvzgvkihn0cmluzw== ';
This is an encoded string
echo Base64_decode ($STR);
?>

get_headers-get the server to respond to all headers sent by an HTTP request
Get_headers () returns an array that contains the headers sent by the server in response to an HTTP request. If it fails, it returns false and emits an e_warning level error message.
If the optional format parameter is set to 1, Get_headers () parses the corresponding information and sets the array's key name.

The

copy Code code is as follows:
!--? php $phpha 1 = get_headers (' http://www.php.net ');
$phpha 2 = get_headers (' http://www.php.net ', 1);
Print_r ($phpha 1);
Print_r ($phpha 2);
?

The

Output is as follows:
Copy the code code as follows:
Array
(
[0] = = http/1.1 OK
[1] = server:nginx/1.2.2
[2] = Date:tue, 10:17:59 GMT
[3] = content-type:text/html; Charset=utf-8
[4] = Conn Ection:close
[5] = x-powered-by:php/5.3.8
[6] = x-pingback:http://www.php.net/xmlrpc.php
[7] = = via:10.67.15.26
[8] = set-cookie:saeut=124.127.138.35.1352197078737175; path=/; max-age=311040000
)
Array
(
[0] = http/1.1 + OK
[Server] = nginx/1.2.2
[Date] = Tue, Nov 10:17:59 GMT
[Content-type] = text/html; Charset=utf-8
[Connection] = Close
[x-powered-by] = php/5.3.8
[X-pingback] = http://www.php.net /xmlrpc.php
[Via] = 10.67.15.21
[Set-cookie] = saeut=124.127.138.35.1352197079055460; path=/; max-age= 311040000
)

get_meta_tags-extracts all meta tags from a file content property, returns an array
As you can imagine, some websites can easily use this function for website SEO information extraction.

Copy the Code code as follows:
Tianya PHP Blog Http://www.php.net
$phpha = get_meta_tags (' http://www.php.net ');
Print_r ($phpha);
?>

The output is as follows:
Copy the Code code as follows:
Array
(
[keywords] = Tianya blog, PHP blog, PHP technology blog, PHP Learning blog, PHP development Blog
[description] + tianya PHP blog is a PHP-based learning blog, record Phper learning process, pay attention to the latest developments in the Internet.
[Generator] = WordPress 3.2.1
)

http_build_query-the request string after generating Url-encode

$url = Array (' c ' = = ' blog ', ' a ' = ' show ', ' id ' =>10, ' hello ', ' world ');
C=blog&a=show&id=10&0=hello&1=world
echo Http_build_query ($url);
C=blog&a=show&id=10&phpha_0=hello&phpha_1=world
Echo http_build_query ($url, ' php_ ');
?>
[/code]

This function I used most of the place is to make a variety of APIs, the combination of request URL, very convenient.
You can also see that you can specify a prefix for the members of the numeric index within the array.

parse_url-parse URL, return its components
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 validate the legitimacy of a given URL, but to decompose it into the parts listed below. An incomplete URL is also accepted, and Parse_url () tries to parse it as correctly as possible.

Copy the Code code as follows:
$url = ' Http://tianya:php.net@php.com/hello.php?id=10#nav ';
Print_r (Parse_url ($url));
?>
Array
(
[Scheme] = http
[Host] = phpha.com
[User] = Tianya
[Pass] = phphadotcom
[Path] =/hello.php
[Query] = id=10
[Fragment] = Nav
)

rawurlencode-encoding URLs according to RFC 1738
rawurldecode-decoding encoded URL strings
urlencode-encoded URL string
urldecode-decoding encoded URL strings

Copy the Code code as follows:
$url = ' http://www.php.net Tianya ';
echo UrlEncode ($url);
Echo '
';
echo Rawurlencode ($url);
Echo '
';
echo UrlDecode ($url);
Echo '
';
echo Rawurldecode ($url);
?>

The output is as follows:
Copy the Code code as follows:
Http%3a%2f%2fwww.php.net+tianya
Http%3a%2f%2fwww.php.net%20tianya

As you can see, the difference between UrlEncode and Rawurlencode is:
UrlEncode () encodes the space as a plus sign (+), and Rawurlencode () encodes the space as%20
UrlDecode () and Rawurldecode () are the corresponding decoding functions.

  • Related Article

    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.