"something here ; and there, oh,that's all!"
I want to split it by ; and ,
so after processing should get:
something here
and there
oh
that's all!
"something here ; and there, oh,that's all!"
I want to split it by ; and ,
so after processing should get:
something here
and there
oh
that's all!
<?php
$pattern = '/[;,]/';
$string = "something here ; and there, oh,that's all!";
echo '<pre>', print_r( preg_split( $pattern, $string ), 1 ), '</pre>';
Updated answer to an updated question:
<?php
$pattern = '/[\x{ff0c},]/u';
//$string = "something here ; and there, oh,that's all!";
$string = 'hei,nihao,a ';
echo '<pre>', print_r( preg_split( $pattern, $string ), 1 ), '</pre>';
The split() PHP funcition allows the delimiter to be a regular expression. Unfortunately it's deprecated and will be removed in PHP6
The preg_split() function should be OK, and it returns an array:
$results = preg_split('[;,]/', $string);
and there are a few extra optional parameters which may be useful.
Is the first delimiter character in your edited example actually a 2 byte Unicode character?
Perhaps the preg_slit() function is treating the delimiter as three characters and splitting between the characters of the unicode (Chinese?) 'character'