Current Location: Home> Function Categories> rawurlencode

rawurlencode

Encoding URLs according to RFC 3986
Name:rawurlencode
Category:URLs
Programming Language:php
One-line Description:URL encodes the string, converts special characters to a hexadecimal ASCII value, and prepends each special character with a percent sign (%)

Function name: rawurlencode()

Applicable versions: PHP 4, PHP 5, PHP 7

Usage: rawurlencode(string $str): string

Function description: The rawurlencode() function URL encodes the string, converts special characters into an ASCII value represented in hexadecimal, and prepends each special character with a percent sign (%).

parameter:

  • $str: The string to be URL encoded.

Return value: Returns the URL encoded string.

Example:

 // 示例1: $str = "Hello World!"; $encodedStr = rawurlencode($str); echo $encodedStr; // 输出:Hello%20World%21 // 示例2: $str = "hello@php.net"; $encodedStr = rawurlencode($str); echo $encodedStr; // 输出:hello%40php.net // 示例3: $str = "中文"; $encodedStr = rawurlencode($str); echo $encodedStr; // 输出:%E4%B8%AD%E6%96%87

Notes:

  • The rawurlencode() function does not encode the following characters: letters, numbers, underscores, hyphens, and dots.
  • Special characters include all characters except the above characters, such as spaces, Chinese characters, special symbols, etc.
  • If you need to use the encoded string for query strings in the URL, you can use the urlencode() function.
  • If you need to use the encoded string for query strings in the path, you can use the rawurlencode() function.
  • After encoding using the rawurlencode() function, you can use the rawurldecode() function to decode.
Similar Functions
Popular Articles