简体   繁体   English

PHP中的Base64编码不适用于'&'和'#'吗?

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

My knowledge about base64 is pretty limited. 我对base64的了解非常有限。 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(); 我正在使用它作为内容管理系统中字符串转义的替代方法,因为已经警告我如何在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; PHP似乎在字符串中#或&的实例之后截断了所有内容; 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. 另外,请评论一下使用base64来保持CMS中帖子内容的“真实性”是否只是明智之举,还是明智之举。

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 您可以在Wikipediaphp手册中找到有关base64的信息

Thank you all, Dav was right all the way. 谢谢大家,达夫一直都是对的。 A simple URLEncode function I grabbed off Google did the trick :) 我从Google手中抢到的一个简单的URLEncode函数就完成了:)

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

Thanks again :) 再次感谢 :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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