网站制作学习网PHP→正文:php 正则匹配获取汉字
字体:

php 正则匹配获取汉字

PHP 2014/3/4 10:29:06  点击:不统计

%77w%77%2E%66%6F%72%61%73%70%2E%63%6E

 php正则获取汉字,并将汉字结果返回来,在做采集数据时用到了正则获取
<?php
header('Content-type: text/html; charset=UTF-8');
$forasp="forasp.cn网站制作学习网www.forasp.cn正则获取中文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网站制作学习网"
    [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) "网站制作学习网hidden_content$"
    [1]=>
    string(18) "正则获取中文"
    [2]=>
    string(12) "获取中文"
  }
}
这样就把中文汉字匹配出来了,如果中间需要其他内容匹配则需要进行正则上的修改。

学习www.网for站asp制.cn作

·上一篇:ajax 跨域 php ajax跨域 >>    ·下一篇:php获取前一天后一天 >>
推荐文章
最新文章