简体   繁体   中英

Base64 encoding in PHP not working for '&' and '#'?

My knowledge about base64 is pretty limited. I am using it as an alternative to string escaping in a content management system, for I had been warned about how weaknesses have been found in mysql_real_escape_string(); and quite sheepishly so, as I am aware of how it buffs text size up.

PHP seems to truncate everything after an instance of # or & in the string; please help me out of this one.

Also, comment on whether using base64 to maintain the 'trueness' of post content in the CMS is just plain retarded, or a wise move.

Thanks for your time :)

Yes it works:

$ php
<?php echo base64_decode(base64_encode("hello &# world")); ?>
hello &# world

you can find informations about base64 on wikipedia and in php manual

Thank you all, Dav was right all the way. A simple URLEncode function I grabbed off Google did the trick :)

return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').
                                                                replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+');

Thanks again :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM