| Newsgroups |
php.notes |
| Message-ID |
<[email protected]> |
Using the flags requires passing a limit option even if you desire no limit, use 0 or -1.
Otherwise the result is unexpected, as the flags, being predefined constants, are integers and will be taken as the split limit not the flag as intended.
echo PREG_SPLIT_DELIM_CAPTURE,' ', PREG_SPLIT_NO_EMPTY,' ', PREG_SPLIT_OFFSET_CAPTURE,"\n";
echos: 2 1 4
print_r(preg_split('//', '131.95M', PREG_SPLIT_NO_EMPTY) );
produces array: [ '131.95M']
as limit is actually set to 1
print_r( preg_split('//', '131.95M', 0, PREG_SPLIT_NO_EMPTY) );
produces array: [ "1", "3", "1", ".", "9", "5", "M"]
print_r( preg_split('/([[:alpha:]])/', '131.95M', PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY) );
produces array: [ '131.95', '']
print_r( preg_split('/([[:alpha:]])/', '131.95M', -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY) );
produces array: [ '131.95', 'M']
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.5.137 (proxied: 2001:8003:4016:7800:b117:17d8:7e86:db80)
----
Manual Page -- https://php.net/manual/en/function.preg-split.php
Edit -- https://main.php.net/note/edit/130187
Del: integrated -- https://main.php.net/note/delete/130187/integrated
Del: useless -- https://main.php.net/note/delete/130187/useless
Del: bad code -- https://main.php.net/note/delete/130187/bad+code
Del: spam -- https://main.php.net/note/delete/130187/spam
Del: non-english -- https://main.php.net/note/delete/130187/non-english
Del: in docs -- https://main.php.net/note/delete/130187/in+docs
Del: other reasons-- https://main.php.net/note/delete/130187
Reject -- https://main.php.net/note/reject/130187
Search -- https://main.php.net/manage/user-notes.php