Php base base64 编码和解码无法正常工作
Php base base64 encode and decode not working correctly
我想使用 base64 在 php 中进行编码和解码,但是编码和解码函数没有给我正确的输出。我正在使用来自 online php functions 的代码。
我对这个字符串进行编码
"best arabic songs loves 2013 nonstop أفضل من الأغاني الحب الجديد
كلمات العربي"
并得到输出:
"YmVzdCBhcmFiaWMgc29uZ3MgbG92ZXMgMjAxMyBub25zdG9wINij2YHYttmEINmF2YYg2KfZhNij2LrYp9mG2Yog2KfZhNit2Kgg2KfZhNis2K/ZitivINmD2YTZhdin2Kog2KfZhNi52LHYqNmK"
当我使用这个 php 代码时,它没有给出正确的编码和解码字符串:
$str = 'best arabic songs loves 2013 nonstop أفضل من الأغاني الحب الجديد كلمات العربي';
$decodestr = base64_decode($str);
echo 'decode = '.$decodestr
$encodestr = base64_encode($decodestr );
echo '<br>';
echo 'encode = '.$encodestr;
i got this output :
decode = më-j¶›‰Ë(ž%¢÷¬ÛMwž‰ì¶Š
encode = bestarabicsongsloves2013nonstoo=
任何人都可以帮助我如何使用 php 中的 base64 编码和解码函数获得正确的编码和解码字符串?
函数 base64_decode 只解码已经 base64 编码的块。
在您的代码中,您正在尝试对导致问题的纯文本进行 base64 解码。
<?php $str = 'best arabic songs loves 2013 nonstop أفضل من الأغاني الحب الجديد كلمات العربي'; $encodestr = base64_encode($str); echo 'Base64 encoding of "best arabic songs loves 2013 nonstop أفضل من الأغاني الحب الجديد كلمات العربي" = '.'<br><br>'.$encodestr; $decodestr=base64_decode($encodestr); echo '<br><br><br>'; echo 'Base64 decoding of "best arabic songs loves 2013 nonstop أفضل من الأغاني الحب الجديد كلمات العربي" = '.'<br><br>'.$decodestr; ?>
试试这个代码:它对我来说很好用!
您也可以使用此 PHP 来 encode/decode 您的 base64。
<?php
/*To encode A string into base64 in PHP: */
$str = "I am Krypton-X"; /*This is your string*/
$encode = base64_encode($str); /*Encode*/
echo("$encode"); /*print base64*/
?>
将base64解码为PHP
中的字符串
<?php
$base = "SSBhbSBLcnlwdG9uLVg=";
/*Your base64 encoded data */
$decode = base64_decode($base); /*Decode*/
echo("$decode"); /* print string */
?>
我想使用 base64 在 php 中进行编码和解码,但是编码和解码函数没有给我正确的输出。我正在使用来自 online php functions 的代码。
我对这个字符串进行编码
"best arabic songs loves 2013 nonstop أفضل من الأغاني الحب الجديد كلمات العربي"
并得到输出:
"YmVzdCBhcmFiaWMgc29uZ3MgbG92ZXMgMjAxMyBub25zdG9wINij2YHYttmEINmF2YYg2KfZhNij2LrYp9mG2Yog2KfZhNit2Kgg2KfZhNis2K/ZitivINmD2YTZhdin2Kog2KfZhNi52LHYqNmK"
当我使用这个 php 代码时,它没有给出正确的编码和解码字符串:
$str = 'best arabic songs loves 2013 nonstop أفضل من الأغاني الحب الجديد كلمات العربي';
$decodestr = base64_decode($str);
echo 'decode = '.$decodestr
$encodestr = base64_encode($decodestr );
echo '<br>';
echo 'encode = '.$encodestr;
i got this output :
decode = më-j¶›‰Ë(ž%¢÷¬ÛMwž‰ì¶Š
encode = bestarabicsongsloves2013nonstoo=
任何人都可以帮助我如何使用 php 中的 base64 编码和解码函数获得正确的编码和解码字符串?
函数 base64_decode 只解码已经 base64 编码的块。 在您的代码中,您正在尝试对导致问题的纯文本进行 base64 解码。
<?php $str = 'best arabic songs loves 2013 nonstop أفضل من الأغاني الحب الجديد كلمات العربي'; $encodestr = base64_encode($str); echo 'Base64 encoding of "best arabic songs loves 2013 nonstop أفضل من الأغاني الحب الجديد كلمات العربي" = '.'<br><br>'.$encodestr; $decodestr=base64_decode($encodestr); echo '<br><br><br>'; echo 'Base64 decoding of "best arabic songs loves 2013 nonstop أفضل من الأغاني الحب الجديد كلمات العربي" = '.'<br><br>'.$decodestr; ?>
试试这个代码:它对我来说很好用!
您也可以使用此 PHP 来 encode/decode 您的 base64。
<?php
/*To encode A string into base64 in PHP: */
$str = "I am Krypton-X"; /*This is your string*/
$encode = base64_encode($str); /*Encode*/
echo("$encode"); /*print base64*/
?>
将base64解码为PHP
中的字符串<?php
$base = "SSBhbSBLcnlwdG9uLVg=";
/*Your base64 encoded data */
$decode = base64_decode($base); /*Decode*/
echo("$decode"); /* print string */
?>