Summary of php commonly used url processing functions

  • 2021-08-05 09:08:33
  • OfStack

This paper summarizes several url encoding parsing functions in php, such as parse_url, rawurldecode, rawurlencode, urldecode and urlencode. Share them for your reference. The specific usage is as follows:

Here's an introduction and example: parse_url ($str url);

Convert url to an array: print_r (parse_url ("www. ofstack. com")); Parse url and output return array, url special format string is restored to ordinary string.

Syntax: string rawurldecode (string str);

Return value: String

Function type: encoding processing

Content Description: This function will string decoding, from url string special format solution to ordinary string, detailed encoding and decoding information and specification file can refer to rfc 1738, code as follows:

echo rawurldecode('foo%20bar%40baz');      // Output foo bar@baz 
string rawurlencode ( string str )

Returns a string, All non-alphanumeric characters in this string except -_. are replaced with a percent sign (%) followed by two 106-digit digits, This encoding is described in rfc 1738 to protect literal characters from being interpreted as special url delimiters, and to protect the url format from being cluttered by transmission media, like some mail systems, using character conversions, for example, if you want to include a password in url of ftp:

 
$str="https://www.ofstack.com";       // Definition string
$result=rawurlencode($str);      // Encodes the specified string
echo $result;
/*
urldecode()
url Decoding
*/   // Output result
$str="http%3a%2f%2fwww.ofstack.com";
$result=urldecode($str);
echo $result;
/*
urlencode()
url Code
*/
$str="https://www.ofstack.com";  // Definition string
$result=urlencode($str);   // Encodes the specified string
echo $result;  // Output result

I hope this article is helpful to everyone's PHP programming.


Related articles: