首页 > 编程知识 正文

包含preg_searchphp的词条

时间:2024-04-24 11:43:09 阅读:333790 作者:QPZA

本文目录一览:

php超长文本截取函数

?php

function  unhtml($content){

$content=htmlspecialchars($content);

$content=str_replace(chr(13),"br",$content);

$content=str_replace(chr(32),"br",$content);

$content=str_replace("[_[","",$content);

$content=str_relace(")_)","",$content);

$content=str_replace("|_|","",$content);

$search = array ("'script[^]*?.*?/script'si",  // 去掉 javascript

 "'[/!]*?[^]*?'si",           // 去掉 HTML 标记

 "'([rn])[s]+'",                 // 去掉空白字符

 "'(quot|#34);'i",                 // 替换 HTML 实体

 "'(amp|#38);'i",

 "'(lt|#60);'i",

 "'(gt|#62);'i",

 "'(nbsp|#160);'i",

 "'(iexcl|#161);'i",

 "'(cent|#162);'i",

 "'(pound|#163);'i",

 "'(copy|#169);'i",

 "'#(d+);'e","|'|isU",'|"|isU');                    // 作为 PHP 代码运行

$replace = array ("",

  "",

  "\1",

  """,

  "",

  "",

  "",

  " ",

  chr(161),

  chr(162),

  chr(163),

  chr(169),

  "chr(\1)","","");

$content = preg_replace ($search, $replace, $content);

rerurn trim($content);

}

?

请教大家一个关于PHP搜索的问题

search.php文件中可以这样写(思路)

$sql=select * from zhigong where id1;("先写一个都允许查询的条件,方便下面连接sql语句")

if(!empty($_POST['a']) !is_null($_POST['a'])){

$xm=htmlspecialchars($_POST['a'])//简单的先防止sql注入

$sql.=" and xm='{$xm}'";

}

if(!empty($_POST['b']) !is_null($_POST['b'])){

$sj=htmlspecialchars($_POST['b'])//简单的先防止sql注入

$sql.=" and sj='{$sj}'";

}

if(!empty($_POST['d']) !is_null($_POST['d'])){

$xb=htmlspecialchars($_POST['d'])//简单的先防止sql注入

$sql.=" and xb='{$xb}'";

}

PHP preg_replace 重复内容的替换次数问题

你这不是已经写了函数吗?

function tihuan($abb,$d){

return preg_replace("/1/",$d,$abb,1);

}

这就是函数啊.

你可以改一下,把要查找的字符串也写成参数.

function tihuan($search,$to = '',$source_str,$times = 1){

if(empty($search)) return '';

if(empty($source_str)) return '';

return preg_replace($search,$to,$source_str,$times);

}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。