且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

检测base64编码在PHP?

更新时间:2023-02-26 13:39:52

base64_de code()返回FALSE。你也可以考虑为pre-验证一个普通的前pression,但base64_de code应该是足够的,除非你有大量的数据进行测试。当然,任何文本可能看像恩的base64 codeD文本,但随机文本满足要求的概率是相当低的。

base64_decode() returns FALSE if the input is not valid base64 encoded data. You could also consider a regular expression for pre-validation, but base64_decode should be enough unless you have huge amounts of data to test. Naturally, any text may "look" like base64 encoded text, but the probability for random text fulfilling the requirements is quite low.

校正:要获得字符集的测试,你需要通过真正作为第二个参数base64_de code在为了得到严格的检查。此外,它似乎并不即使在严格模式在意填充,所以如果你的base64 EN codeD的内容应该是正确填补你可能还需要检查(检查其长度为四的倍数)

Correction: To get the character set test, you'll need to pass true as the second argument to base64_decode in order to get strict checking. Also, it doesn't seem to care about padding even in strict mode, so if your base64 encoded content is supposed to be correctly padded you might also want to check that (check that its length is a multiple of four).