项目中需要用到去除汉字的方法,整理的资料


$file = fopen("hb/hacktea8.txt","r+") or exit("Unable to open file!");
while(!feof($file)){
$line=fgets($file);
$pattern = "/[\x{4E00}-\x{9FFF}]+/u";
echo preg_replace($pattern, '', $line);
echo "<br />";
}
fclose($file);

 
从txt文件中取出每一行,并去除每一行中的非汉字。
1.取出一行用fgets()函数
2.去除非汉字使用正则函数preg_replace()
3.非汉字的正则  /[^\x{4E00}-\x{9FFF}]+/  ,注意php中,不能用\u****表示unicode字符,要用\x{****}
4.u表示修正符

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-28
  • 2021-09-21
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-10-03
  • 2022-12-23
  • 2021-11-11
  • 2022-12-23
  • 2021-09-16
  • 2021-11-30
相关资源
相似解决方案