PHP: json_decode dumping NULL, BOM not found
- by SerEnder
I've been trying to find out why this 'json_encode'd string isn't parsing out correctly, and came across previously answered questions that had the UTF BOM sequence that was throwing the error, but didn't help me here.
Here's the code that isn't currently working:
//Decode the notes attached to the sig
$aNotes = json_decode($rule->getNotes(),true);
$bom = pack("CCC",0xef,0xbb,0xbf);
if(0 == strncmp($rule->getNotes(),$bom,3))
{
print('BOM detected - json encoding in UTF-8<br/>');
}
else
{
print('BOM NOT detected - json encoding correctly<br/>');
}
print('rule->getNotes:<br/>' . $rule->getNotes() .'<br/>');
var_dump($aNotes);
Which generates this result:
BOM NOT detected - json encoding correctly
rule->getNotes:
[{"lDate":"Unknown","sAuthor":"Unknown","sNote":"This is a general purpose Russian spam rule that matches anything starting with 2, 3 or 4 hex digits followed by a domain name ending with .ru -RSK 2010-05-10"},{"lDate":"1295031463082","sAuthor":"Drew Thorstenson","sNote":"this is Ryan's ru rule"}]
NULL
I've run it through JSON Lint, which said it was valid, and An Online JSON Parser which parsed it correctly too.
Any insight would be greatly appreciated.