PHP implode limit bug?

拜拜、爱过 提交于 2020-01-15 23:02:52

问题


I've got a script that creates an array with around 40,000 entries, PHP arrays have no limit except the memory of the server...

However the PHP function implode() simply does not output anything, when trying to implode an array of around 40,000 entries into a string. Each array entry has about a sentence worth of a-Z characters. No memory errors, no errors at all!

Can anyone confirm this?

I'm not sure its possible to post examples!

EDIT (2013-06-03):

I can confirm that the PHP memory limit was set to -1 and PHP errors were to to E_ALL. There where no errors and simply no output. This seems to be an bug with PHP of some sort.

I was using echo implode("<br>\n", $myLogArr); with did not error or output anything, I've mananage to get the correct expected result by using foreach ($myLogArr as $line) echo $line."<br>\n";


回答1:


The following works just fine - with 50,000 entries.

<?php
$arr = array();
for ($i = 0; $i < 50000; $i++) {
    $arr[] = str_shuffle('This sentance is of average length, which The Internet says is about 14.2 words.');
}
echo implode(PHP_EOL, $arr);

I would suggest increasing error_reporting and attempting to debug this further.

Anthony.




回答2:


memory_limit to -1 and then execute your script in try catch block




回答3:


$string = str_repeat("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz,",1000000);
$array = explode(",", $string);
var_dump(sizeof($array), strlen(implode(",", $array)));

outputs:

int 1000001
int 53000000

OP, can you please show your code?



来源:https://stackoverflow.com/questions/16860094/php-implode-limit-bug

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!