代码之家  ›  专栏  ›  技术社区  ›  wwilkins

在一堆ISO-889-1网页中查找非法字符的最佳方法?

  •  0
  • wwilkins  · 技术社区  · 16 年前

    我有一个 网站中的html文件,这些文件创建于2000年,并一直保持至今。我们最近开始努力用html实体替换非法字符。一页一页地寻找版权符号和商标标签似乎是一件很麻烦的事。你们有谁知道有一个应用程序会接收大量html文件,并告诉我在哪里需要用html实体替换非法字符?

    3 回复  |  直到 16 年前
        1
  •  0
  •   Franz    16 年前

    您可以编写一个PHP脚本(如果可以;如果不能,我很乐意提供帮助),但我假设您已经转换了一些“特殊字符”,因此这确实会使任务变得更加困难(尽管我仍然认为这是可能的)。。。

        2
  •  0
  •   Raj More    16 年前

    任何好的文本编辑器都会为您搜索文件内容并返回匹配列表。

    EditPlus . 有几位编辑像我一样 Notepad++ , TextPad

    您不必打开这些文件。您只需指定存储文件的路径、掩码(*.html)和要搜索的内容“”,编辑器将返回匹配列表,双击时,它将打开文件并显示匹配行。

        3
  •  0
  •   Dr Flodo    14 年前

    我还有一个网站,需要定期在字符集之间来回转换大量文件名。虽然文本编辑器可以做到这一点,但在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); 
    }                                                                                            
    
    推荐文章