php正則獲取漢字,并將漢字結(jié)果返回來,在做采集數(shù)據(jù)時用到了正則獲取
<?php
header('Content-type: text/html; charset=UTF-8');
$forasp="forasp.cn網(wǎng)站制作學(xué)習(xí)網(wǎng)正則獲取中文php獲取中文";
$cn = "/(cn|php)([x{4e00}-\x{9fa5}]*)/u";
preg_match_all($cn,$forasp,$return);
var_dump($return);
?>
array(3) {
[0]=>
array(3) {
[0]=>
string(23) "cn網(wǎng)站制作學(xué)習(xí)網(wǎng)"
[1]=>
string(20) "cn正則獲取中文"
[2]=>
string(15) "php獲取中文"
}
[1]=>
array(3) {
[0]=>
string(2) "cn"
[1]=>
string(2) "cn"
[2]=>
string(3) "php"
}
[2]=>
array(3) {
[0]=>
string(21) "網(wǎng)站制作學(xué)習(xí)網(wǎng)hidden_content$"
[1]=>
string(18) "正則獲取中文"
[2]=>
string(12) "獲取中文"
}
}
這樣就把中文漢字匹配出來了,如果中間需要其他內(nèi)容匹配則需要進(jìn)行正則上的修改。
更多信息請查看IT技術(shù)專欄