PHP代码背后的逻辑

I'm having trouble understanding the logic behind the following code:

Initial code

            <?php
            $output_arr=array();
            $handle = fopen("../etc/init.d/bandwidthlimiters/rulestest", "r");
            if ($handle) {

                $i=1;
                while (($line = fgets($handle)) !== false) {

                $test_string=$line;
                $test_string=str_replace(" htb rate ","@@",$test_string);
                $test_string=str_replace("kbit ceil ","@@",$test_string);

                $tmp = explode("@@", $test_string);
                array_push($output_arr,$tmp[1]);
                $i++;
               }

                fclose($handle);
            } else {
                // error opening the file.
            } 

            echo $output_arr[5]
            ?>

At the moment echo $output_arr[5] provides a printed value of "5" when taken from the file source listed. File contents shown below, under "New Output".

New Output

Instead of looking for values between " htb rate " and "kbit ceil", I would like it to grab results based on the following terms: " ceil " and "kbit"

tc class add dev br-lan parent 1:1 classid 1:2 htb rate 1kbit ceil 11111kbit
tc class add dev br-lan parent 1:1 classid 1:3 htb rate 2kbit ceil 22222kbit
tc class add dev br-lan parent 1:1 classid 1:4 htb rate 3kbit ceil 33333kbit
tc class add dev br-lan parent 1:1 classid 1:5 htb rate 4kbit ceil 44444kbit
tc class add dev br-lan parent 1:1 classid 1:6 htb rate 5kbit ceil 55555kbit

By using the sample lines above, the new result should retrieve "55555", instead of the original "5"

Modified version

I have tried a modification, as shown below:

                $test_string=str_replace(" ceil ","@@",$test_string);
                $test_string=str_replace("kbit","@@",$test_string);

However, this does not return any result. For future use, I would like to be able to manipulate this further to return different results again, in which case, any explanation of how to use this method would be appreciated.

Your modification is resulting in this value of $test_string:

tc class add dev br-lan parent 1:1 classid 1:6 htb rate 5@@@@55555@@

Notice that there are two @@ sequences before the field that you want to retrieve. The first comes from replacing kbit, the second comes from replacing ceil. When you explode it, you get:

array(4) {
  [0]=>
  string(57) "tc class add dev br-lan parent 1:1 classid 1:6 htb rate 5"
  [1]=>
  string(0) ""
  [2]=>
  string(5) "55555"
  [3]=>
  string(1) "
"
}

So 55555 is in $tmp[2], not $tmp[1].