Microsoft Word - Core PHP Programming Using PHP to Build Dynamic Web Sites

(singke) #1

array preg_split(string pattern, string text, integer limit)


The preg_split function returns an array of substrings from the text argument. The
pattern argument will be used as a field delimiter. The optional limit argument sets
the maximum number of elements to return. This function is equivalent to split.


<?


$paragraph = "This is a short paragraph. Each ";
$paragraph .= "sentence will be extracted by ";
$paragraph .= "the preg_split function. As a ";
$paragraph .= "result, you will be amazed!";
$sentence = preg_split("/[.!\?]/", $paragraph);


for($index = 0; $index < count($sentence);
$index++)
{
print("$index. $sentence[$index]
\n");
}
?>

Free download pdf