I am trying to use json_encode
on a big array, and the result returns nothing (yes, I checked that it is utf-8). When I started to investigate this issue I found that the problem arise when a string becomes bigger than 65536.
So when my array is of size 1245, its string from json_encode
has length of string(65493), but when I increase array by just one, the string becomes longer than 65536, json_encode fails to output any result.
I thought that the problem is because of memory limit
, but when I checked my php.ini I see that it is -1.
Any idea what can be a problem?
Basically I am doing something like this:
$arr = array();
for($i =0; $i<9000; $i++){
$arr[] = array(
'name' => 'test',
'str' => md5($i)
);
}
echo '<pre>'.json_encode($arr).'</pre>';
P.S. sorry guys. I found the problem, thanks to a person with an unreprintable name :-) (thank your Lawrence).
<pre>
is the culprit... for some reason it does not print the string in my browser, but it is there.
Lawrence, if you want, you can just write it and I will accept it as correct. Because you were the reason that I came up with this.