简单的中文分词算法,二元分词的PHP代码:
$str = '苏杭,人间的天堂paradise!';
//$str = iconv('GB2312','UTF-8',$str);
$result = spStr($str);
print_r($result);
/**
* UTF-8版 中文二元分词
*/
function spStr($str)
{
$cstr = array();
$search = array(",", "/", "\\", ".", ";", ":", "\"", "!", "~", "`", "^", "(", ")", "?", "-", "\t", "\n", "'", "<", ">", "\r", "\r\n", "{1}quot;", "&", "%", "#", "@", "+", "=", "{", "}", "[", "]", ":", ")", "(", ".", "。", ",", "!", ";", "“", "”", "‘"