本文目錄一覽:
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 標記
“‘([\r\n])[\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);
}
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/297824.html