$save=str_replace("<font color=red>关键字</font> ","关键字",$save);

解决方案 »

  1.   

    srt_replace()这个函数是什么意思?to zpfleaf(啊风)上面的这句话应该加在什么地方呢?
    谢谢!
      

  2.   

    放在你要显示这个字符串之前的任何地方。
    是替换的意思。将$save中的"关键字"替换成"<font color=red>关键字</font> "
      

  3.   

    srt_replace()--->str_replace()
    字符串处理函数库
    str_replace
    字符串取代。语法: string str_replace(string needle, string str, string haystack);返回值: 字符串函数种类: 资料处理
     
     
    内容说明 
    本函数将字符串 str 代入 haystack 字符串中,将所有的 needle 置换成 str。[email protected] (11-Apr-1999) 指出在 PHP 3.0.7 版,本函数有些 bug,而 [email protected] (05-Jun-1999) 补充在 PHP 3.0.8 版本函数就回复正常了。
     
     
    使用范例 
    下例将 %body% 以 black 取代<?php
    $bodytag = str_replace("%body%", "black", "<body text=%body%>");
    echo $bodytag;
    ?>  
      

  4.   

    我的一段代码,搜索目录下的文件,带分页显示,关键字加亮
    有点乱,我自己都懒得看了$Search = trim($Search);                                
    $recordnum = 10; //每页显示的记录数
    echo "<div align=right><font color=#003399>关键字</font><font color=red>".$Search."</font></div>";
    $to = "<font color=red>".$Search."</font>";
    //读取文件目录到数组
    $handle=opendir('./updata');
    while ($file = readdir($handle)) {
    if (!is_dir($file)){
    $dir[$i] = './updata/'.$file;
    $i++;}}
    $count = count($dir);
    //echo $count;
    closedir($handle); 
    $handle=opendir('../JBFG');
    while ($file = readdir($handle)) {
    if (!is_dir($file)){
    $dir[$count] = '../JBFG/'.$file;
    $count++;}}
    closedir($handle);
    if (empty($on)){
      $start = 1;
      for ($j=1;$j<=$count;$j++){
        $path = $dir[$j];
        if (!empty($path)){
          $fp = fopen($path,"r");
          while ($buffer = fgetss($fp,4096)){
    if (strstr($buffer,$Search)){
      $num++;
      break;}
          }
         }
       }
    $pagenum=bcdiv($num+$recordnum-1,$recordnum,0);//分成页面数 
    $pageno = 1;//当前页
    }
    echo "<tr height=10><td></td></tr>";
    echo "<tr><font color=#003399 size=2>共</font><font color=red size=2>".$pagenum."</font><font color=#003399 size=2>页&nbsp;&nbsp;&nbsp;&nbsp;";
    echo "<font color=red>".$pageno."</font><font color=#003399>/".$pagenum."</font><tr>";
    //显示记录
    //piv
    if ($on!="2"){
    $n1 = 0;
    for ($j=$start;$j<=count($dir);$j++){
      while ($number <= $recordnum){
        $path = $dir[$j];
          if (!empty($path)){
    $fp = fopen($path,"r");
    while ($buffer = fgetss($fp,4096)){
      if (strstr($buffer,$Search)){
    //取title
    $title = "无标题文档";
    $file = file($path);
    foreach ($file as $value){
                      $value = strtolower($value);
      if (strstr($value,"<title>")){
         $tit = explode("<title>",$value);
         foreach ($tit as $value){
          if (strstr($value,"</title>")){
            $title = explode("</title>",$value);
    }
         }
      }
    }     
        $Result = '';
        $buffer = strip_tags(Chop(ltrim($buffer)));
        $find = explode($Search,$buffer);
        for ($k=0;$k<=5;$k++){ 
          if (!empty($find[$k])){
            $Result.= $find[$k].$to;
          }   
        }
      if (is_array($title))
      $top = $title[0];
      else
      $top = $title;
      echo '<tr><td><a href="'.$path.'" target="_blank"><font color=black size = 2>>>'.$top.'</font></a></td></tr>';
      echo '<tr><td><font size = 2 color=#58595B>'.$Result.'......</font></td></tr>';
      echo '<tr><td>&nbsp;</td></tr>';
      $number++;
      break;
              }
            }
          }
           $n1++; 
       break;
       }
      }
    echo '<tr><td>';
    //上一页
       echo '<div align="right"><font size=2>';
    if ($pageno>1){
       $priv=$pageno-1; 
       $start1 = $start-1;
       echo '<a href="FGSS.php?&count='.$count.'&Search='.$Search.'&start='.$start1.'&pageno='.$priv.'&pagenum='.$pagenum.'&on=2">上一页</a>&nbsp;&nbsp;&nbsp;&nbsp;'; 
       }
    //下一页
    if ($pageno<$pagenum){
       $end = $start1+$n1+1;
       $next=$pageno+1;
       echo '<a href="FGSS.php?&count='.$count.'&Search='.$Search.'&start='.$end.'&pageno='.$next.'&pagenum='.$pagenum.'&on=1">下一页</a>'; 
       }
    echo '</font></div></td></tr>';
    }
    //back
    if ($on=="2"){
    $n2 = 0;
    for ($j=$start;$j>=0;$j--){
      while ($number <= $recordnum){
        $path = $dir[$j];
          if (!empty($path)){
    $fp = fopen($path,"r");
    while ($buffer = fgetss($fp,4096)){
      if (strstr($buffer,$Search)){
    //取title
    $title = "无标题文档";
    $file = file($path);
    foreach ($file as $value){
                      $value = strtolower($value);
      if (strstr($value,"<title>")){
         $tit = explode("<title>",$value);
         foreach ($tit as $value){
          if (strstr($value,"</title>")){
            $title = explode("</title>",$value);
    }
         }
      }
    }     
        $Result = '';
        $buffer = strip_tags(Chop(ltrim($buffer)));
        $find = explode($Search,$buffer);
        for ($k=0;$k<=5;$k++){ 
          if (!empty($find[$k])){
            $Result.= $find[$k].$to;
          }   
        }
      if (is_array($title))
            $top[$number]= $title[0];
      else
      $top[$number]=$title;
      $link[$number]=$path;
      $butten[$number]=$Result;
      $number++;   
      break;
              }
            }
          }
       $n2++;
       break;
       }
     }
    for ($m=count($link)-1;$m>=1;$m--){
    echo '<tr><td><a href="'.$link[$m].'" target="_blank"><font color=black size=2>>>'.$top[$m].'</font></a></td></tr>';
    echo '<tr><td><font color=#58595B size=2>'.$butten[$m].'......</font></td></tr>';
    echo '<tr><td>&nbsp;</td></tr>';
    }
    echo '<tr><td>';
    //上一页
       echo '<div align="right"><font size=2>';
    if ($pageno>1){
        $priv=$pageno-1; 
        $start1 = $start-$n2;
        echo '<a href="FGSS.php?&count='.$count.'&Search='.$Search.'&start='.$start1.'&pageno='.$priv.'&pagenum='.$pagenum.'&on=2">上一页</a>&nbsp;&nbsp;&nbsp;&nbsp;'; 
        }
    //下一页
    if ($pageno<$pagenum){
        $end = $start+1;
        $next=$pageno+1;
        echo '<a href="FGSS.php?&count='.$count.'&Search='.$Search.'&start='.$end.'&pageno='.$next.'&pagenum='.$pagenum.'&on=1">下一页</a>'; 
        } 
    }
    echo '</font></div></font></div></td></tr>';