Hướng dẫn urldecode php - urldecode php

(Php 4, Php 5, Php 7, Php 8)

URLDECODE-Chuỗi được mã hóa URL được mã hóaDecodes URL-encoded string

Sự mô tả

Urldecode (Chuỗi $string): Chuỗi(string $string): string

Thông số

string

Chuỗi được giải mã.

Trả về giá trị

Trả về chuỗi được giải mã.

Ví dụ

Ví dụ #1 urldecode () ví dụurldecode() example

$query "my=apples&are=green+and+red";

foreach (

explode('&'$query) as $chunk) {
    
$param explode("="$chunk);

    if (

$param) {
        
printf("Value for parameter \"%s\" is \"%s\"
\n"
urldecode($param[0]), urldecode($param[1]));
    }
}
?>

Ghi chú

Cảnh báo

Superglobals $ _Get và $ _Request đã được giải mã. Sử dụng urldecode () trên một phần tử trong $ _get hoặc $ _Request có thể có kết quả bất ngờ và nguy hiểm.urldecode() on an element in $_GET or $_REQUEST could have unexpected and dangerous results.

Xem thêm

  • urlencode () - Chuỗi mã hóa url
  • RAWURLENCODE () - Mã điện tử URL theo RFC 3986
  • RawUrldecode () - Chuỗi mã hóa URL giải mã
  • »& NBSP; RFC 3986

Alejandro tại Devenet Dot Net

11 năm trước

When the client send Get data, utf-8 character encoding have a tiny problem with the urlencode.
Consider the "º" character.
Some clients can send (as example)
foo.php?myvar=%BA
and another clients send
foo.php?myvar=%C2%BA (The "right" url encoding)

in this scenary, you assign the value into variable $x

$x = $_GET['myvar'];
?>

$x store: in the first case "�" (bad) and in the second case "º" (good)

To fix that, you can use this function:

function to_utf8( $string ) {
// From http://w3.org/International/questions/qa-forms-utf-8.html
   
if ( preg_match('%^(?:
      [\x09\x0A\x0D\x20-\x7E]            # ASCII
    | [\xC2-\xDF][\x80-\xBF]             # non-overlong 2-byte
    | \xE0[\xA0-\xBF][\x80-\xBF]         # excluding overlongs
    | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}  # straight 3-byte
    | \xED[\x80-\x9F][\x80-\xBF]         # excluding surrogates
    | \xF0[\x90-\xBF][\x80-\xBF]{2}      # planes 1-3
    | [\xF1-\xF3][\x80-\xBF]{3}          # planes 4-15
    | \xF4[\x80-\x8F][\x80-\xBF]{2}      # plane 16
)*$%xs'
, $string) ) {
        return
$string;
    } else {
        return
iconv( 'CP1252', 'UTF-8', $string);
    }
}
?>

and assign in this way:

string0

string1

string2

string3

string4

string5

Trực quan ¶

16 năm trước

string6

Jan Vratny ¶

14 năm trước

string7

string8

string5

Tomas tại Penajaca dot com dot br ¶

19 năm trước

$query "my=apples&are=green+and+red";0

$query "my=apples&are=green+and+red";1

$query "my=apples&are=green+and+red";2

$query "my=apples&are=green+and+red";3

$query "my=apples&are=green+and+red";4

string5

Matt Johnson ¶

17 năm trước

$query "my=apples&are=green+and+red";6

$query "my=apples&are=green+and+red";7

$query "my=apples&are=green+and+red";8

$query "my=apples&are=green+and+red";9

foreach (0

foreach (1

foreach (2

foreach (3

string5

rosty dot kerei tại gmail dot com ¶

16 năm trước

foreach (5

foreach (6

foreach (7

foreach (8

foreach (9

explode('&'$query) as $chunk) {
    
$param explode("="$chunk);

    if (

$param) {
        
printf("Value for parameter \"%s\" is \"%s\"
\n"
urldecode($param[0]), urldecode($param[1]));
    }
}
?>
0

string5

Jan Vratny ¶

14 năm trước

explode('&'$query) as $chunk) {
    
$param explode("="$chunk);

    if (

$param) {
        
printf("Value for parameter \"%s\" is \"%s\"
\n"
urldecode($param[0]), urldecode($param[1]));
    }
}
?>
2

explode('&'$query) as $chunk) {
    
$param explode("="$chunk);

    if (

$param) {
        
printf("Value for parameter \"%s\" is \"%s\"
\n"
urldecode($param[0]), urldecode($param[1]));
    }
}
?>
3

explode('&'$query) as $chunk) {
    
$param explode("="$chunk);

    if (

$param) {
        
printf("Value for parameter \"%s\" is \"%s\"
\n"
urldecode($param[0]), urldecode($param[1]));
    }
}
?>
4

Tomas tại Penajaca dot com dot br ¶

14 năm trước

explode('&'$query) as $chunk) {
    
$param explode("="$chunk);

    if (

$param) {
        
printf("Value for parameter \"%s\" is \"%s\"
\n"
urldecode($param[0]), urldecode($param[1]));
    }
}
?>
5

explode('&'$query) as $chunk) {
    
$param explode("="$chunk);

    if (

$param) {
        
printf("Value for parameter \"%s\" is \"%s\"
\n"
urldecode($param[0]), urldecode($param[1]));
    }
}
?>
6

explode('&'$query) as $chunk) {
    
$param explode("="$chunk);

    if (

$param) {
        
printf("Value for parameter \"%s\" is \"%s\"
\n"
urldecode($param[0]), urldecode($param[1]));
    }
}
?>
7

explode('&'$query) as $chunk) {
    
$param explode("="$chunk);

    if (

$param) {
        
printf("Value for parameter \"%s\" is \"%s\"
\n"
urldecode($param[0]), urldecode($param[1]));
    }
}
?>
8

string5

Tomas tại Penajaca dot com dot br ¶

19 năm trước

When the client send Get data, utf-8 character encoding have a tiny problem with the urlencode.
Consider the "º" character.
Some clients can send (as example)
foo.php?myvar=%BA
and another clients send
foo.php?myvar=%C2%BA (The "right" url encoding)
0

When the client send Get data, utf-8 character encoding have a tiny problem with the urlencode.
Consider the "º" character.
Some clients can send (as example)
foo.php?myvar=%BA
and another clients send
foo.php?myvar=%C2%BA (The "right" url encoding)
1

string5

Matt Johnson ¶

19 năm trước

When the client send Get data, utf-8 character encoding have a tiny problem with the urlencode.
Consider the "º" character.
Some clients can send (as example)
foo.php?myvar=%BA
and another clients send
foo.php?myvar=%C2%BA (The "right" url encoding)
3

When the client send Get data, utf-8 character encoding have a tiny problem with the urlencode.
Consider the "º" character.
Some clients can send (as example)
foo.php?myvar=%BA
and another clients send
foo.php?myvar=%C2%BA (The "right" url encoding)
4

When the client send Get data, utf-8 character encoding have a tiny problem with the urlencode.
Consider the "º" character.
Some clients can send (as example)
foo.php?myvar=%BA
and another clients send
foo.php?myvar=%C2%BA (The "right" url encoding)
5

string5

Matt Johnson ¶

17 năm trước

When the client send Get data, utf-8 character encoding have a tiny problem with the urlencode.
Consider the "º" character.
Some clients can send (as example)
foo.php?myvar=%BA
and another clients send
foo.php?myvar=%C2%BA (The "right" url encoding)
7

rosty dot kerei tại gmail dot com ¶

14 năm trước

When the client send Get data, utf-8 character encoding have a tiny problem with the urlencode.
Consider the "º" character.
Some clients can send (as example)
foo.php?myvar=%BA
and another clients send
foo.php?myvar=%C2%BA (The "right" url encoding)
8

When the client send Get data, utf-8 character encoding have a tiny problem with the urlencode.
Consider the "º" character.
Some clients can send (as example)
foo.php?myvar=%BA
and another clients send
foo.php?myvar=%C2%BA (The "right" url encoding)
9

in this scenary, you assign the value into variable $x 0

in this scenary, you assign the value into variable $x 1

string5

Tomas tại Penajaca dot com dot br ¶

17 năm trước

in this scenary, you assign the value into variable $x 3

in this scenary, you assign the value into variable $x 4

in this scenary, you assign the value into variable $x 5

in this scenary, you assign the value into variable $x 6

in this scenary, you assign the value into variable $x 7

in this scenary, you assign the value into variable $x 8

in this scenary, you assign the value into variable $x 9

$x = $_GET['myvar'];
?>

$x store: in the first case "�" (bad) and in the second case "º" (good)
0

string5

rosty dot kerei tại gmail dot com ¶

Ozlperez11 tại gmail dot com ¶

$x = $_GET['myvar'];
?>

$x store: in the first case "�" (bad) and in the second case "º" (good)
2

$x = $_GET['myvar'];
?>

$x store: in the first case "�" (bad) and in the second case "º" (good)
3

$x = $_GET['myvar'];
?>

$x store: in the first case "�" (bad) and in the second case "º" (good)
4

$x = $_GET['myvar'];
?>

$x store: in the first case "�" (bad) and in the second case "º" (good)
5

$x = $_GET['myvar'];
?>

$x store: in the first case "�" (bad) and in the second case "º" (good)
6

string5

7 năm trước

19 năm trước

$x = $_GET['myvar'];
?>

$x store: in the first case "�" (bad) and in the second case "º" (good)
8

Matt Johnson ¶

17 năm trước

$x = $_GET['myvar'];
?>

$x store: in the first case "�" (bad) and in the second case "º" (good)
9

To fix that, you can use this function: 0

To fix that, you can use this function: 1

To fix that, you can use this function: 2

string5

rosty dot kerei tại gmail dot com ¶

19 năm trước

To fix that, you can use this function: 4

To fix that, you can use this function: 5

To fix that, you can use this function: 6

To fix that, you can use this function: 7

To fix that, you can use this function: 8

To fix that, you can use this function: 9

function to_utf8( $string ) {
// From http://w3.org/International/questions/qa-forms-utf-8.html
   
if ( preg_match('%^(?:
      [\x09\x0A\x0D\x20-\x7E]            # ASCII
    | [\xC2-\xDF][\x80-\xBF]             # non-overlong 2-byte
    | \xE0[\xA0-\xBF][\x80-\xBF]         # excluding overlongs
    | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}  # straight 3-byte
    | \xED[\x80-\x9F][\x80-\xBF]         # excluding surrogates
    | \xF0[\x90-\xBF][\x80-\xBF]{2}      # planes 1-3
    | [\xF1-\xF3][\x80-\xBF]{3}          # planes 4-15
    | \xF4[\x80-\x8F][\x80-\xBF]{2}      # plane 16
)*$%xs'
, $string) ) {
        return
$string;
    } else {
        return
iconv( 'CP1252', 'UTF-8', $string);
    }
}
?>

and assign in this way:
0

function to_utf8( $string ) {
// From http://w3.org/International/questions/qa-forms-utf-8.html
   
if ( preg_match('%^(?:
      [\x09\x0A\x0D\x20-\x7E]            # ASCII
    | [\xC2-\xDF][\x80-\xBF]             # non-overlong 2-byte
    | \xE0[\xA0-\xBF][\x80-\xBF]         # excluding overlongs
    | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}  # straight 3-byte
    | \xED[\x80-\x9F][\x80-\xBF]         # excluding surrogates
    | \xF0[\x90-\xBF][\x80-\xBF]{2}      # planes 1-3
    | [\xF1-\xF3][\x80-\xBF]{3}          # planes 4-15
    | \xF4[\x80-\x8F][\x80-\xBF]{2}      # plane 16
)*$%xs'
, $string) ) {
        return
$string;
    } else {
        return
iconv( 'CP1252', 'UTF-8', $string);
    }
}
?>

and assign in this way:
1

string5

Matt Johnson ¶

19 năm trước

function to_utf8( $string ) {
// From http://w3.org/International/questions/qa-forms-utf-8.html
   
if ( preg_match('%^(?:
      [\x09\x0A\x0D\x20-\x7E]            # ASCII
    | [\xC2-\xDF][\x80-\xBF]             # non-overlong 2-byte
    | \xE0[\xA0-\xBF][\x80-\xBF]         # excluding overlongs
    | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}  # straight 3-byte
    | \xED[\x80-\x9F][\x80-\xBF]         # excluding surrogates
    | \xF0[\x90-\xBF][\x80-\xBF]{2}      # planes 1-3
    | [\xF1-\xF3][\x80-\xBF]{3}          # planes 4-15
    | \xF4[\x80-\x8F][\x80-\xBF]{2}      # plane 16
)*$%xs'
, $string) ) {
        return
$string;
    } else {
        return
iconv( 'CP1252', 'UTF-8', $string);
    }
}
?>

and assign in this way:
3

function to_utf8( $string ) {
// From http://w3.org/International/questions/qa-forms-utf-8.html
   
if ( preg_match('%^(?:
      [\x09\x0A\x0D\x20-\x7E]            # ASCII
    | [\xC2-\xDF][\x80-\xBF]             # non-overlong 2-byte
    | \xE0[\xA0-\xBF][\x80-\xBF]         # excluding overlongs
    | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}  # straight 3-byte
    | \xED[\x80-\x9F][\x80-\xBF]         # excluding surrogates
    | \xF0[\x90-\xBF][\x80-\xBF]{2}      # planes 1-3
    | [\xF1-\xF3][\x80-\xBF]{3}          # planes 4-15
    | \xF4[\x80-\x8F][\x80-\xBF]{2}      # plane 16
)*$%xs'
, $string) ) {
        return
$string;
    } else {
        return
iconv( 'CP1252', 'UTF-8', $string);
    }
}
?>

and assign in this way:
4

string5

Matt Johnson ¶

19 năm trước

function to_utf8( $string ) {
// From http://w3.org/International/questions/qa-forms-utf-8.html
   
if ( preg_match('%^(?:
      [\x09\x0A\x0D\x20-\x7E]            # ASCII
    | [\xC2-\xDF][\x80-\xBF]             # non-overlong 2-byte
    | \xE0[\xA0-\xBF][\x80-\xBF]         # excluding overlongs
    | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}  # straight 3-byte
    | \xED[\x80-\x9F][\x80-\xBF]         # excluding surrogates
    | \xF0[\x90-\xBF][\x80-\xBF]{2}      # planes 1-3
    | [\xF1-\xF3][\x80-\xBF]{3}          # planes 4-15
    | \xF4[\x80-\x8F][\x80-\xBF]{2}      # plane 16
)*$%xs'
, $string) ) {
        return
$string;
    } else {
        return
iconv( 'CP1252', 'UTF-8', $string);
    }
}
?>

and assign in this way:
6

function to_utf8( $string ) {
// From http://w3.org/International/questions/qa-forms-utf-8.html
   
if ( preg_match('%^(?:
      [\x09\x0A\x0D\x20-\x7E]            # ASCII
    | [\xC2-\xDF][\x80-\xBF]             # non-overlong 2-byte
    | \xE0[\xA0-\xBF][\x80-\xBF]         # excluding overlongs
    | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}  # straight 3-byte
    | \xED[\x80-\x9F][\x80-\xBF]         # excluding surrogates
    | \xF0[\x90-\xBF][\x80-\xBF]{2}      # planes 1-3
    | [\xF1-\xF3][\x80-\xBF]{3}          # planes 4-15
    | \xF4[\x80-\x8F][\x80-\xBF]{2}      # plane 16
)*$%xs'
, $string) ) {
        return
$string;
    } else {
        return
iconv( 'CP1252', 'UTF-8', $string);
    }
}
?>

and assign in this way:
7

function to_utf8( $string ) {
// From http://w3.org/International/questions/qa-forms-utf-8.html
   
if ( preg_match('%^(?:
      [\x09\x0A\x0D\x20-\x7E]            # ASCII
    | [\xC2-\xDF][\x80-\xBF]             # non-overlong 2-byte
    | \xE0[\xA0-\xBF][\x80-\xBF]         # excluding overlongs
    | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}  # straight 3-byte
    | \xED[\x80-\x9F][\x80-\xBF]         # excluding surrogates
    | \xF0[\x90-\xBF][\x80-\xBF]{2}      # planes 1-3
    | [\xF1-\xF3][\x80-\xBF]{3}          # planes 4-15
    | \xF4[\x80-\x8F][\x80-\xBF]{2}      # plane 16
)*$%xs'
, $string) ) {
        return
$string;
    } else {
        return
iconv( 'CP1252', 'UTF-8', $string);
    }
}
?>

and assign in this way:
8

string5