Splitting characters, Words, Sentences using Preg_Split

Splitting characters, Words, Sentences using Preg_Split

Syntax : array preg_split ( string pattern, string subject [, int limit [, int flags]])

The following example illustrates splitting characters, words and sentences from input string using preg_split() funtion.

<?php

$input = ‘Hello user!. Welcome.’;

$split_chars = preg_split(’//’, $input);

print_r($split_chars);

echo “<p>”;

$split_words= preg_split(’/ /’, $input);

print_r($split_words);

echo “<p>”;

$split_sentences= preg_split(’/\./’, $input, -1 , PREG_SPLIT_NO_EMPTY);

print_r($split_sentences);

?>

Leave a Reply

You must be logged in to post a comment.


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.