1--TEST-- 2json_decode() invalid UTF8 3--SKIPIF-- 4<?php 5if (!extension_loaded("json")) print "skip"; 6?> 7--FILE-- 8<?php 9function json_decode_invalid_utf8($str) { 10 var_dump(json_decode($str)); 11 var_dump(json_decode($str, true, 512, JSON_INVALID_UTF8_IGNORE)); 12 $json = json_decode($str, true, 512, JSON_INVALID_UTF8_SUBSTITUTE); 13 if (is_array($json)) { 14 var_dump(array_map(function($item) { return bin2hex($item); }, $json)); 15 } else { 16 var_dump(bin2hex($json)); 17 } 18} 19json_decode_invalid_utf8("\"a\xb0b\""); 20json_decode_invalid_utf8("\"a\xd0\xf2b\""); 21json_decode_invalid_utf8("\"\x61\xf0\x80\x80\x41\""); 22json_decode_invalid_utf8("[\"\xc1\xc1\",\"a\"]"); 23echo "Done\n"; 24?> 25--EXPECT-- 26NULL 27string(2) "ab" 28string(10) "61efbfbd62" 29NULL 30string(2) "ab" 31string(16) "61efbfbdefbfbd62" 32NULL 33string(2) "aA" 34string(22) "61efbfbdefbfbdefbfbd41" 35NULL 36array(2) { 37 [0]=> 38 string(0) "" 39 [1]=> 40 string(1) "a" 41} 42array(2) { 43 [0]=> 44 string(12) "efbfbdefbfbd" 45 [1]=> 46 string(2) "61" 47} 48Done 49