$ Temp [0] = "abc ";
$ Temp [1] = 123;
$ Temp [2] = "us .";
$ Temp [3] = 5;
$ Temp [4] = 58;
$ Temp [5] = "cs ";
// The code above defines an array with both numbers and strings
Echo "the contents of the array temp are :";
Echo "<p> ";
// Output array content through loop
For ($ I = 0; $ I <count ($ temp); $ I ++)
{
Echo $ temp [$ I];
Echo ",";
}
Echo "<p> ";
Echo "the new array after processing by preg_grep () is :";
$ Temp2 = preg_grep ("/^ (d) d */", $ temp); // use preg_grep for processing
// In the above regular expression mode, "//" is the delimiter and its content is all integer elements.
Echo "<p> ";
Print_r ($ temp2); // outputs the content of the new array through loop
//
$ Str = 'string'; // define a string
$ Chars = preg_split ('//', $ str,-1, preg_split_no_empty); // use a regular expression to perform the split operation.
Print_r ($ chars); // output result array: array ([0] => s [1] => t [2] => r [3] => I [4] => n [5] => g)
//
$ String = "L 15,200 3"; // define a string
$ Pattern = "/(w +) (d +), (d +)/I"; // define the matching mode
$ Replacement = "$ {1} 1, $3"; // define the replacement content
Print preg_replace ($ pattern, $ replacement, $ string); // output result april1, 2003
//
$ Text = "maid day is 04/01/2002 n"; // define a string
$ Text. = "last christmas was 12/24/2001 n"; // String Update
$ Pattern = "| (d {2}/d {2}/) (d {4}) |"; // defines the matching mode
Function next_year ($ matches) // defines the callback function
{
Return $ matches [1]. ($ matches [2] + 1); // return value
}
$ Result = preg_replace_callback ($ pattern, "next_year", $ text); // use the callback function to perform search and replace
Echo $ result; // output result "maid was 12/24/2002"
//
$ Keywords = "'php '"; // define a string
$ Keywords = preg_quote ($ keywords, "'"); // Escape "'"
Echo $ keywords;
?>