Edit report at https://bugs.php.net/bug.php?id=55842&edit=1

 ID:                 55842
 Comment by:         lennart dot ohrstedt at diadoker dot se
 Reported by:        lennart dot ohrstedt at diadoker dot se
 Summary:            Explode function sensitive to data!
 Status:             Feedback
 Type:               Bug
 Package:            Strings related
 Operating System:   Mac OS x 10.7.1,MAMP 1.9.6
 PHP Version:        5.3SVN-2011-10-04 (SVN)
 Block user comment: N
 Private report:     N

 New Comment:

<?php
    $fil_in = "test_new.php";
    $fil_out = "test2.php";
    if ( file_exists($fil_in) )
                        {
                                $file_in = fopen($fil_in,"r+");                 
                                $file_out = fopen($fil_out,"w+");
                        }
    while(!feof($file_in))
            {
                $line_in=fgets($file_in); 
                $line_array=explode(">",$line_in);              
        }
        $j=count($line_array);
        for ($i=0;$i<($j-1);$i++)
                {
                        $line_out=$line_array[$i];
                        fwrite($file_out,$line_out.">"."\n"); 
                }   
        fclose($file_in);
    fclose($file_out);                                                          
                
?>


Previous Comments:
------------------------------------------------------------------------
[2011-10-04 12:58:19] [email protected]

Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.



------------------------------------------------------------------------
[2011-10-04 11:38:23] lennart dot ohrstedt at diadoker dot se

Description:
------------
If I have a string containing "<?php" somewhere in the middle and I use explode 
to split the string. Then the output array will not have the part of the string 
prior to the "<?php", the output array will start at the character following 
the 
"<?php". Is this a bug or this is the way explode works?

Test script:
---------------
use URL www.diadoker.se/test/packa_upp.php. The input file, "test_new.php", to 
this is a previus "packed" php-file using "trim", and the output is to file  
"test2.php".

Expected result:
----------------
I expected the result to be equal to the input but split according to the 
parameters in the explode function. 

Actual result:
--------------
When there is the characters "<?php" somewhere in the string, everything before 
these characters are lostand the first character in the output array is the 
character following the "<?php".


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=55842&edit=1

Reply via email to