php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76185 preg_split Removes Empty lines when flag is not set
Submitted: 2018-04-04 23:58 UTC Modified: 2018-06-24 04:25 UTC
From: will at bisbeefamily dot com Assigned:
Status: No Feedback Package: *General Issues
PHP Version: 5.6, 7.1 & 7.2.3 OS: Windows 10/Apache
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
4 + 1 = ?
Subscribe to this entry?

 
 [2018-04-04 23:58 UTC] will at bisbeefamily dot com
Description:
------------
$parts = preg_split( "#^\s*%(\w+):#sm", $buffer, null, PREG_SPLIT_OFFSET_CAPTURE|PREG_SPLIT_DELIM_CAPTURE ); 

Removes empty lines between the split targets even though the PREG_SPLIT_NO_EMPTY flag is not set.




Test script:
---------------
         


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-04-05 00:10 UTC] requinix@php.net
-Status: Open +Status: Feedback
 [2018-04-05 00:10 UTC] requinix@php.net
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.

But did you know that \s will match newline characters?
 [2018-04-06 04:15 UTC] will at bisbeefamily dot com
-Status: Feedback +Status: Open -PHP Version: 5.6.35 +PHP Version: 5.6, 7.1 & 7.2.3
 [2018-04-06 04:15 UTC] will at bisbeefamily dot com
<?php
$buffer = "
%target:admin_media.php%
%location:%
$showmedia_url = getURL( 'showmedia', 1 );
%end:%
%insert:after%



// ****** following line added by Showfolio mod ******
$showfolio_url = getURL( 'showfolio', 1 );



%end:%

";

// STANDARDIZE LINE ENDINGS
$buffer = preg_replace( "#(?:\r\n|\r\r\n|[\r\n])#", "\r\n", $buffer );

// CREATE WORKING TABLE
$parts = preg_split( "#^\s*%(\w+):#m", $buffer, NULL, PREG_SPLIT_OFFSET_CAPTURE|PREG_SPLIT_DELIM_CAPTURE );

print_r( $parts );
?>
 [2018-04-06 04:24 UTC] requinix@php.net
-Status: Open +Status: Feedback
 [2018-04-06 04:24 UTC] requinix@php.net
https://3v4l.org/jKupd

The output looks correct to me. What are you expecting to see?
 [2018-06-24 04:25 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 03 11:01:32 2024 UTC