From 5d7cdfbcc5f338b97f3fcbd595f5790eae7e192a Mon Sep 17 00:00:00 2001 From: Monte Ohrt Date: Mon, 31 Jul 2000 16:11:27 +0000 Subject: [PATCH] update preg_split() and preg_quote examples git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@29415 c90b9560-bf6c-de11-be94-00142212c4b1 --- functions/pcre.xml | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/functions/pcre.xml b/functions/pcre.xml index b6404f5921..8d0351e3be 100644 --- a/functions/pcre.xml +++ b/functions/pcre.xml @@ -474,13 +474,10 @@ $text = preg_replace ($search, $replace, $document); Getting parts of 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"); - - This example splits the text by any number of spaces or - commas. So the resulting $keywords array would be ("hypertext", - "language", "programming") - See also preg_match, preg_match_all, and @@ -533,19 +530,17 @@ echo $keywords; // returns \$40 for a g3\/400 Italicizing a word within some text + +// In this example, preg_quote($word) is used to keep the +// asterisks from having special meaning to the regular +// expression. + $textbody = "This book is *very* difficult to find."; $word = "*very*"; -$textbody = preg_replace ("|\b".preg_quote($word)."\b|", +$textbody = preg_replace ("/".preg_quote($word)."/", "<i>".$word."</i>", $textbody); - - In this example, preg_quote($word) is used to keep the - asterisks from having special meaning to the regular - expression. The \b is recognized by pcre to find a word - boundary, so only whole words match. This way something like - "is*very*difficult" would not be considered a match. - @@ -577,8 +572,9 @@ $textbody = preg_replace ("|\b".preg_quote($word)."\b|", <function>preg_grep</function> example -preg_grep ("/^(\d+)?\.\d+$/", $array); // find all array elements - // containing floating point numbers +// return all array elements +// containing floating point numbers +$fl_array = preg_grep ("/^(\d+)?\.\d+$/", $array);