|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2010-10-20 20:44 UTC] phpuser at thankyou2010 dot com
Description:
------------
preg_split fails on some specific input, which seems to be caused by a subpattern. If in the testcode I reduce the length of the string in between the middle [..], it works fine.
Test script:
---------------
<?php
$input = '[a][012345678901234 ][a]';
// first match a [, then anything but spaces, end with ]
$tokens = preg_split('/\\[([^\\s]*)*\\]/U', $input);
print_r($tokens);
$tokens = preg_split('/\\[[^\\s]*\\]/U', $input);
print_r($tokens);
Expected result:
----------------
Array
(
[0] =>
[1] => [012345678901234 ]
[2] =>
)
Array
(
[0] =>
[1] => [012345678901234 ]
[2] =>
)
Actual result:
--------------
Array
(
[0] =>
[1] => [012345678901234 ][a]
)
Array
(
[0] =>
[1] => [012345678901234 ]
[2] =>
)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 05:00:02 2025 UTC |
This is because the default backtrack_limit size. Set it to a big value so it will work. e.g. ini_set('pcre.backtrack_limit', PHP_INT_MAX); $input = '[a][012345678901234 ][a]'; $tokens = preg_split('/\\[([^\\s]*)*\\]/U', $input); print_r($tokens); You can check the preg_last_error() return to detect such errors.