From 45cbabb3158184e81570fc1ccc87d07406026612 Mon Sep 17 00:00:00 2001 From: Torben Wilson Date: Sun, 10 Sep 2000 22:46:43 +0000 Subject: [PATCH] Added another example to preg_split() and a pointer to it from split(), addressing what seems to be a common request in the notes from people coming from perl. git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@32418 c90b9560-bf6c-de11-be94-00142212c4b1 --- functions/pcre.xml | 35 +++++++++++++++++++++++++++-------- functions/regex.xml | 11 +++++++++++ 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/functions/pcre.xml b/functions/pcre.xml index 6e0052c3f7..95c39dd01f 100644 --- a/functions/pcre.xml +++ b/functions/pcre.xml @@ -457,37 +457,56 @@ $text = preg_replace ($search, $replace, $document); + Parameter flags was added in PHP 4 Beta 3. + Returns an array containing substrings of subject split along boundaries matched by pattern. + If limit is specified, then only substrings up to limit are returned. + - If flags is PREG_SPLIT_NO_EMPTY then only non-empty pieces will - be by preg_split. + If flags is PREG_SPLIT_NO_EMPTY then only + non-empty pieces will be by preg_split. - - - Getting parts of search string - + + + <function>preg_split</function> example + + Get the parts of a search string. + + // split the phrase by any number of commas or space characters, // which include " ", \r, \t, \n and \f $keywords = preg_split ("/[\s,]+/", "hypertext language, programming"); - - + + + + Splitting a string into component characters. + + +$str = 'string'; +$chars = preg_split('//', $str, 0, PREG_SPLIT_NO_EMPTY); +print_r($chars); + + + + See also preg_match, preg_match_all, and preg_replace. + diff --git a/functions/regex.xml b/functions/regex.xml index d83712b61c..abf989347a 100644 --- a/functions/regex.xml +++ b/functions/regex.xml @@ -335,14 +335,23 @@ echo "Month: $month; Day: $day; Year: $year<br>\n"; + Note that pattern is case-sensitive. + Note that if you don't require the power of regular expressions, it is faster to use explode, which doesn't incur the overhead of the regular expression engine. + + + For users looking for a way to emulate perl's $chars = + split('', $str) behaviour, please see the examples for + preg_split. + + Please note that pattern is a regular expression. If you want to split on any of the characters which @@ -355,10 +364,12 @@ echo "Month: $month; Day: $day; Year: $year<br>\n"; something along the lines of man /usr/local/src/regex/regex.7 in order to read it. + See also: spliti, explode, and implode. +