我在2000年创建的网站中有一个束的html文件,并且一直维护到今天。我们最近开始尝试用他们的html实体替换非法字符。转到页面寻找版权符号和商标标签似乎是一件苦差事。你们有没有人知道一个应用程序需要一堆html文件并告诉我在哪里需要用html实体替换非法字符?
答案 0 :(得分:0)
任何好的文本编辑器都会为您搜索文件内容并返回匹配列表。
我使用EditPlus执行此操作。有几个编辑器,如Notepad++,TextPad等,可以轻松帮助您完成此任务。
您无需打开文件。您只需指定存储文件的路径和Mask(* .html)以及搜索“©”的内容,编辑器将返回匹配列表,当您双击时,它会打开文件并带来匹配线。
答案 1 :(得分:0)
你可以写一个PHP脚本(如果可以的话;如果没有,我很乐意提供帮助),但我认为你已经转换了一些“特殊字符”,所以这确实使任务变得更难(虽然我仍然认为这是可能的)......
答案 2 :(得分:0)
我还有一个网站需要定期在字符集之间来回转换大量文件名。虽然文本编辑器可以做到这一点,但是在php中使用2个步骤的可移植解决方案是可取的。首先,将文件名添加到数组中,然后执行搜索和替换。函数中的一段额外代码会从数组中排除某些文件类型。
Function listdir($start_dir='.') {
$nonFilesArray=array('index.php','index.html','help.html'); //unallowed files & subfolders
$filesArray = array() ; // $filesArray holds new records and $full[$j] holds names
if (is_dir($start_dir)) {
$fh = opendir($start_dir);
while (($tmpFile = readdir($fh)) !== false) { // get each filename without its path
if (strcmp($tmpFile, '.')==0 || strcmp($tmpFile, '..')==0) continue; // skip . & ..
$filepath = $start_dir . '/' . $tmpFile; // name the relative path/to/file
if (is_dir($filepath)) // if path/to/file is a folder, recurse into it
$filesArray = array_merge($filesArray, listdir($filepath));
else // add $filepath to the end of the array
$test=1 ; foreach ($nonFilesArray as $nonfile) {
if ($tmpFile == $nonfile) { $test=0 ; break ; } }
if ( is_dir($filepath) ) { $test=0 ; }
if ($test==1 && pathinfo($tmpFile, PATHINFO_EXTENSION)=='html') {
$filepath = substr_replace($filepath, '', 0, 17) ; // strip initial part of $filepath
$filesArray[] = $filepath ; }
}
closedir($fh);
} else { $filesArray = false; } # no such folder
return $filesArray ;
}
$filesArray = listdir($targetdir); // call the function for this directory
$numNewFiles = count($filesArray) ; // get number of records
for ($i=0; $i<$numNewFiles; $i++) { // read the filenames and replace unwanted characters
$tmplnk = $linkpath .$filesArray[$i] ;
$outname = basename($filesArray[$i],".html") ; $outname = str_replace('-', ' ', $outname);
}