php for循环冻结循环时

When I tried to get variables while looping it just froze my screen and I got following error:

Fatal error: Maximum execution time of 30 seconds exceeded in /home/diligenceh/domains/diligencehelps.com/public_html/upload_lesson.php on line 16

The loop:

$lesson_count       = preg_replace('#[^0-9]#', '', $_POST['description_count']);
for($i = 1; $i <= $lesson_count; $i++)
{
    $image_url_ + $i = $_POST['image_url_'+ $i];
    echo $image_url_ + $i;
}

I think that your code must be something like this:

$_POST['description_count'] = preg_replace('#[^0-9]#', '', $_POST['description_count'], -1, $lesson_count);

for($i = 1; $i <= $lesson_count; $i++) {
    echo  $_POST['image_url_'.$i];
}

pay atention in following:

1.- The 4th parameter in preg_replace() contain the number of replacements made.

2.- The function preg_replace return the original string with the changes. Read the manual here: http://cl1.php.net/manual/en/function.preg-replace.php

3.- I don't understand that what are you trying to do here:

$image_url_ + $i = $_POST['image_url_'+ $i];

you are using plus symbol (+) instead dot (.) to concatenate strings.

Your loop is an endless loop

Try adding like ini_set('max_execution_time', 300); //300 is seconds

Create an array (was that your intention?)

$lesson_count = preg_replace('#[^0-9]#', '', $_POST['description_count']);
$image_url = array();

for($i = 1; $i <= $lesson_count; $i++) {
    $image_url[$i] = $_POST['image_url_'+ $i];
    echo $image_url[$i]; 
}

Also, are you sure $lesson_count is an integer larger than zero? I suspect not, since it is user input. You could try to force it into an integer with

$lesson_count = (int) preg_replace(...);

Update your php.ini file, where you can increase execution time. update max_execution_time which is by default 30

increase your execution time there. for e.g. max_execution_time = 100