[英]PHP Encoding and Decoding HTML as Binary
The database I am using is Postgresql and I downloading a webpage and storing in a BLOB. 我使用的数据库是Postgresql,我下载了一个网页并存储在BLOB中。 Like this:
像这样:
<?php
$html = file_get_contents('http://www.example.com');
$encoded_html = base64_encode($html);
//Store encoded data in blob in database
?>
That part works fine. 那部分工作正常。 But when I try to decode it and display it, it comes out garabled.
但是,当我尝试对其进行解码并显示时,它就变得可靠了。
<?php echo base64_decode($encoded_html); ?>
Do I have to add extra parameters when encoding and decoding the data? 在对数据进行编码和解码时是否需要添加额外的参数?
If this works then the encode/decode functions work fine 如果这可行,那么编码/解码功能就可以正常工作
<?php
$html = file_get_contents('http://www.example.com');
$md5 = md5($html);
$encoded_html = base64_encode($html);
$decoded_html = base64_decode($encoded_html);
echo (md5($decoded_html) == $md5) ? 'OK' : 'FAIL';
echo PHP_EOL;
If not then I'd suggest comparing the base64 data that you're putting into the database with what comes out. 如果没有,那么我建议将您放入数据库中的base64数据与结果进行比较。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.