急~~~~~~~~~~~~~~~~~~~~~~~救! $save=str_replace("<font color=red>关键字</font> ","关键字",$save); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 srt_replace()这个函数是什么意思?to zpfleaf(啊风)上面的这句话应该加在什么地方呢?谢谢! 放在你要显示这个字符串之前的任何地方。是替换的意思。将$save中的"关键字"替换成"<font color=red>关键字</font> " 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;?> 我的一段代码,搜索目录下的文件,带分页显示,关键字加亮有点乱,我自己都懒得看了$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>页 ";echo "<font color=red>".$pageno."</font><font color=#003399>/".$pagenum."</font><tr>";//显示记录//pivif ($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> </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> '; }//下一页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>';}//backif ($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> </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> '; }//下一页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>'; 昨天刚学PHP~~有点小问题~ 用php开发一个大型政府的新闻需要注意什么(急) 介绍几个PHP好点的开源项目 搜索排序问题 请教一个OOP的问题? 向大家请教一个算法问题。。 -----------php开发模式----------大搜索 php如何连接access数据库呢? 实在想..想..想不出来,请大家指点!关于PHP! php如何判断搜索引擎关键词?现在搜索结果页都会二次跳转,$_SERVER['HTTP_REFERER']好像也得不到关键词了,大家怎么解决的? 这个问题谁能帮我解决一下,先谢了! 我的主页无法浏览php sql
谢谢!
是替换的意思。将$save中的"关键字"替换成"<font color=red>关键字</font> "
字符串处理函数库
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;
?>
有点乱,我自己都懒得看了$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>页 ";
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> </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> ';
}
//下一页
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> </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> ';
}
//下一页
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>';