PHP Base64_decode 函式

Sarwan Soomro 2023年1月30日
  1. PHP Base64_decode 函式示例程式碼 1
  2. PHP Base64_decode 函式示例程式碼 2
PHP Base64_decode 函式

PHP base64_decode 函式將字串轉換為長純文字,然後與使用者定義值集的主函式一起傳送。

base64_decode() 是 php 的內建函式,最常用於網路上的郵件功能。

函式語法:

string base64_decode( $string, $strict)

它需要兩個引數。

  1. $string - 用於儲存編碼資料,是必須的。
  2. $strict - 雖然此引數不像前者那樣是強制性的,但當它設定為 TRUE, 時,base64_decode 將返回 FALSE,前提是它的輸入包含函式字母表以外的資料。否則,無效資料將被自動丟棄。

返回值:

base64 解碼函式在失敗的情況下返回 FALSE,並可能返回二進位制值。

PHP Base64_decode 函式示例程式碼 1

<?php
    $string = base64_encode ('Your string values are encoded');
    echo "1.Here is the encoded function value in a machine readable format = ".$string ."<br>";
    echo "2.The function decodes the formerly encoded string value" ."<br>" .base64_decode($string);
?>

輸出:

1.Here is the encoded function value in a machine readable 
format = WW91ciBzdHJpbmcgdmFsdWVzIGFyZSBlbmNvZGVk
2. The function decodes the formerly encoded string value
Your string values are encoded.

示例程式碼顯示了 base64_decode() 函式如何在一個簡單的場景中工作。

為了對編碼資料進行解碼,程式為變數賦值,然後與解碼函式一起使用。

而輸出表明 base64_decode() 如何將資料轉換回使用者可讀格式。

PHP Base64_decode 函式示例程式碼 2

<?php
//The following variable is assigned with a string set 
    $string = "HELLO--こんにちは--你好"; 
//string contains bilingual text 
//base64 is used to encode the data first into the $enco variable
    $enco = base64_encode ($string);
//finally the base64_decode functionis used to decode the encoded value 
    $deco = base64_decode ($enco); 
    echo $deco; 
?>

輸出:

HELLO--こんにちは--你好
作者: Sarwan Soomro
Sarwan Soomro avatar Sarwan Soomro avatar

Sarwan Soomro is a freelance software engineer and an expert technical writer who loves writing and coding. He has 5 years of web development and 3 years of professional writing experience, and an MSs in computer science. In addition, he has numerous professional qualifications in the cloud, database, desktop, and online technologies. And has developed multi-technology programming guides for beginners and published many tech articles.

LinkedIn

相關文章 - PHP Encoding