How to check if a string is base64 valid in PHP

后端 未结 18 1277
执笔经年
执笔经年 2020-12-13 03:41

I have a string and want to test using PHP if it\'s a valid base64 encoded or not.

18条回答
  •  温柔的废话
    2020-12-13 04:07

    You can use this function:

     function is_base64($s)
    {
          return (bool) preg_match('/^[a-zA-Z0-9\/\r\n+]*={0,2}$/', $s);
    }
    

提交回复
热议问题