遍历目录,获取文件中的中文
遍历目录,获取文件中的中文
遍历目录,获取文件中的中文
<?php
/**
*遍历获取文件夹下所有文件中的中文字符
*@author:firmy
*/
$dir = $argv [1];
if (empty ( $dir )) {
help ();
}
/**
* 遍历所有目录
*/
$it = new RecursiveDirectoryIterator ( $dir );
foreach ( new RecursiveIteratorIterator ( $it ) as $file ) {
if (strpos ( $file, "svn" )) {
continue;
}
getChineseWord ( $file );
}
/**
* 获取文件中的中文字符
*
* @param unknown_type $file
*/
function getChineseWord($file) {
$x = file_get_contents ( $file );
if (preg_match_all ( "/([\x{4e00}-\x{9fa5}\x{fe30}-\x{ffa0}]*)/u", $x, $match )) {
foreach ( $match [0] as $k => $v ) {
if (! empty ( $v )) {
$wordList [$v] = $v; // 去重
}
}
}
}
function help() {
echo "
==============================================
请按以下参数运行
php getChineseWord.php 文件夹 > 生成的文件名
==============================================
";
die ();
}
精彩图集
精彩文章






