dede搜索引擎

1.dede模板中的html:

<form action="{dede:fieldname='phpurl'/}/search.php" name="formsearch">
  <inputtype="hidden" name="kwtype" value="1">
  <inputname="keyword" id="keyword" type="text" />
  <selectname="searchtype" id="searchtype">
   <optionvalue="titlekeyword"selected>智能模糊搜索</option>
   <optionvalue="title">仅搜索标题</option>
  </select>
  <inputtype="image" src="{dede:fieldname='templeturl'/}/images/topsearch_submit.gif"/>
</form>

2.search.php代码:

require_once(dirname(__FILE__)."/../include/config_base.php");
require_once(dirname(__FILE__)."/../include/inc_arcsearch_view.php");
$timestamp = time();
$timelock = '../data/time.lock';

if($cfg_allsearch_limit < 1) $cfg_allsearch_limit =1;//cfg_allsearch_limit是网站全局搜索时间限制
if(file_exists($timelock))
{
 if($timestamp - filemtime($timelock)< $cfg_allsearch_limit)
 {
  showmsg('服务器忙,请稍后搜索','-1');
  exit();
 }
}
@touch($timelock,$timestamp);
$channelid = isset($channelid) &&is_numeric($channelid) ? $channelid : 0;
$typeid = isset($typeid) &&is_numeric($typeid) ? $typeid : 0;
if($typeid>0) $channelid = 0;
if(!isset($searchtype)) $searchtype = '';
if($searchtype != 'titlekeyword') $searchtype = 'title';
$cacheid = isset($cacheid) &&is_numeric($cacheid) ? $cacheid : 0;
$kwtype = isset($kwtype) && $kwtype== 0 ? 0 : 1;
$keyword = htmlspecialchars(stripslashes($keyword));
$keyword = ereg_replace("[\"\r\n\t\*\?\(\)\$%']","",trim($keyword));
$keyword = addslashes($keyword);
if( ($cfg_notallowstr!='' &&eregi($cfg_notallowstr,$keyword)) || ($cfg_replacestr!=''&& eregi($cfg_replacestr,$keyword)))
{
 echo "你的信息中存在非法内容,被系统禁止!<ahref='javascript:history.go(-1)'>[返回]</a>";exit();
}
if($keyword=='' || strlen($keyword) < 3 ||strlen($keyword) > 30)
{
 ShowMsg("关键字长度必须要3-30字节之间!","-1");
 exit();
}
$sp = newSearchView($typeid,$keyword,$channelid,$searchtype,$kwtype,$cacheid);
$sp->Display();
$sp->Close();
?>


3.touch函数:

语法:int touch(string filename, int [time]);

返回值:整数

函数种类:文件存取

内容说明

本函数可用来配置最后修改时间。若有指定参数time,则依指定的时间;若无指定时间,则为服务器的时间。和 UNIX 的同名指令一样,若文件不存在,则会建立 filename文件。成功则返回 true 值,其它失败时则返回 false

4.StripSlashes(Stringstr)函数

语法:StripSlashes(Stringstr)

返回值:字符串

函数种类:资料处理

内容说明:本函数可以去掉字符串中的反斜线字符。若是连续两个反斜线,则去掉一个,留下一个。若只有一个反斜线,就直接去掉。

5.htmlspecialchars函数

语法:htmlspecialchars(string,quotestyle,character-set)

 

参数描述
string必需。规定要转换的字符串。
quotestyle

可选。规定如何编码单引号和双引号。

  • ENT_COMPAT -默认。仅编码双引号。
  • ENT_QUOTES -编码双引号和单引号。
  • ENT_NOQUOTES -不编码任何引号。
character-set

可选。字符串值,规定要使用的字符集。

  • ISO-8859-1 - 默认。西欧。
  • ISO-8859-15 - 西欧(增加 Euro符号以及法语、芬兰语字母)。
  • UTF-8 - ASCII 兼容多字节 8 比特Unicode
  • cp866 - DOS 专用 Cyrillic字符集
  • cp1251 - Windows 专用 Cyrillic字符集
  • cp1252 - Windows专用西欧字符集
  • KOI8-R - 俄语
  • GB2312 - 简体中文,国家标准字符集
  • BIG5 - 繁体中文
  • BIG5-HKSCS - Big5香港扩展
  • Shift_JIS - 日语
  • EUC-JP - 日语

 

例子

<html> 
<body>
<?php
$str = "John & 'Adams'";
echo htmlspecialchars($str, ENT_COMPAT);
echo "<br />";
echo htmlspecialchars($str, ENT_QUOTES);
echo "<br />";
echo htmlspecialchars($str, ENT_NOQUOTES);
?>
</body>
</html>

浏览器输出:

John & 'Adams'
John & 'Adams'
John & 'Adams'

如果在浏览器中查看源代码,会看到这些HTML:

<html>
<body>
John &amp; 'Adams'
John &amp; &#039;Adams&#039;
John &amp; 'Adams'
</body>
</html>
  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值