The [man]base64_encode[/man] manual page cites RFC2045, which describes the Base64 encoding format. It's pretty simple to write a function for: after stripping out any characters not in A-Za-z0-9+/= (especially line breaks, which should be present), there should be 0, 1, 2 or 3 = signs at the end (and only at the end), and the number of characters should be a multiple of 4.