开发者

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 开发者_JAVA技巧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 :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜