Examples ¶
Example #1 preg_split() example : Get the parts of a search string
<?php// 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");print_r($keywords);?>
The above example will output:
Array
(
[0] => hypertext
[1] => language
[2] => programming
)
Example #2 Splitting a string into component characters
<?php
$str = 'string';$chars = preg_split('//', $str, -1, PREG_SPLIT_NO_EMPTY);print_r($chars);?>
The above example will output:
Array
(
[0] => s
[1] => t
[2] => r
[3] => i
[4] => n
[5] => g
)
No hay comentarios:
Publicar un comentario