PHP - convert_uudecode() 函式



PHP 的 convert_uudecode() 函式用於解碼 uuencoded 字串。“uuencoded” 字串是使用 UUencoding 方法以“ASCII”文字格式編碼的二進位制資料的表示形式。

您可以將 convert_uuencode() 函式一起使用以執行反向操作。它將解碼後的字串轉換為 uuencoded 字串。

語法

以下是 PHP convert_uudecode() 函式的語法:

convert_uudecode(string $str): string|false

引數

此函式接受一個引數,如下所述:

  • str - 需要解碼的 uuencoded 字串(資料)。

返回值

此函式將解碼後的資料作為字串返回;否則,在失敗時返回“false”。

示例 1

以下是 PHP convert_uudecode() 函式的基本示例:

<?php
   $str = "+22!L;W9E(%!(4\"$`\n`)";
   echo "The given uuencoded string: $str";
   echo "\nThe decoded string is: ";
   #using convert_uudecode() function
   echo convert_uudecode($str);
?>

輸出

以上程式生成以下輸出:

The given uuencoded string: +22!L;W9E(%!(4"$`
`)
The decoded string is: I love PHP!

示例 2

同時使用 convert_uudecode()convert_uuencode() 函式來解碼和編碼資料。

以下是 PHP convert_uudecode() 函式的另一個示例。我們使用此函式來解碼 uuencoded 字串“.5'5T;W)I86QS<&]I;G0` `":

<?php
   $str = ".5'5T;W)I86QS<&]I;G0` `";
   echo "The given uuencoded string: $str";
   echo "\nThe decoded string is: ";
   #using convert_uudecode() function
   echo convert_uudecode($str);
   echo "\nThe encoded string is: ";
   #using convert_uuencode() function
   echo convert_uuencode(convert_uudecode($str));
?>

輸出

執行上述程式後,將顯示以下輸出:

The given uuencoded string: .5'5T;W)I86QS<&]I;G0` `
The decoded string is: Tutorialspoint
The encoded string is: .5'5T;W)I86QS<&]I;G0`
`

示例 3

如果指定的“uuencoded”字串無法解碼,則此函式將返回“false”併發出有關無效資料的警告:

<?php
   $str = "Invalid uuencoded string";
   echo "The given uuencoded string: $str\n";
   echo "The decoded string is: ";
   $decoded = convert_uudecode($str);
   echo "The function returns: ";
   var_dump($decoded);
   if ($decoded === false || $decoded === '') {
       echo "Failed to decode the UUencoded string.";
   } else {
       echo $decoded;
   }
?>

輸出

以下是上述程式的輸出:

The given uuencoded string: Invalid uuencoded string
The decoded string is: PHP Warning:  convert_uudecode(): 
Argument #1 ($data) is not a valid uuencoded string in C:\Apache24\htdocs\index.php on line 5
The function returns: bool(false)
Failed to decode the UUencoded string.
php_function_reference.htm
廣告