本文实例总结了php字符串过滤与替换的方法。分享给大家供大家参考。具体实现方法如下:
复制代码 代码如下:<"\n",$string);//字符串替换
}
//多个空格只保留一个
static public function merge_spaces($string){
return preg_replace("/\s(","\\1",$string);//("/((<br\/","<br>",$string);//---"/"为什么也转义了
}
//过滤字符串中的html标签
static public function strip_tags($string){
return strip_tags($string);
}
//将字符串转换为小写--/--大写
static public function strtolower($string){
return strtolower($string);
}
static public function strtoupper($string){
return strtoupper($string);
}
//过滤字符串开头与结尾的特定字符
static public function trim($string,$char_list='\\\\s'){
$find = array('/[\^\-\]\\\]/S','/\\\{4}/S','/\//');
$replace = array('\\\\\\0','\\','\/');
$char = preg_replace($fine,$replace,$char_list);
$pattern = '^['.$chars.']*|['.$chars.']';
return preg_replace("/$pattern/sSD",'',$string);
}
//过滤字符串中<style>脚本
static public function stric_style($string){
$reg = "/<style[^>]*";
return preg_replace($reg,'',$string);
}
//过滤字符串中html危险代码
static public function strip_html_tags($string){
$reg = "/(\/";
return preg_replace($reg,'',$string);
}
}
?>
希望本文所述对大家的php程序设计有所帮助。
php,字符串,过滤,替换
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
更新日志
- 群星2013-青春缤纷辑压箱宝大公开3CD2[新加坡限量版][WAV整轨]
- 林育群.2013-BalladShow(日本版)【环球】【WAV+CUE】
- 陈加洛.1992-痛到感觉不到【宝丽金】【WAV+CUE】
- 群星.2023-宿命之敌电视剧原声带【韶愔音乐】【FLAC分轨】
- 東京事変-大発見[FLAC+CUE]
- 椎名林檎-三文ゴシップ[FLAC+CUE]
- 2024年08月04日
- 裘德《裘德「最后的水族馆」演唱会LIVE》[320K/MP3][228.89MB]
- 裘德《裘德「最后的水族馆」演唱会LIVE》[24bit 48kHz][FLAC/分轨][2.08G]
- 基因三重奏《如果你什么都不说 音乐会现场录音》[320K/MP3][145.37MB]
- 孟庭苇.1996-月亮说话(2020环球24KGOLD限量版)【上华】【WAV+CUE】
- 群星.1997-新艺宝优质音响系列·国语精选监听版【新艺宝】【WAV+CUE】
- 阿桑.2005-寂寞在唱歌(星外星引进版)【华研国际】【WAV+CUE】
- 基因三重奏《如果你什么都不说 音乐会现场录音》[FLAC/分轨][287.43MB]
- 蔡题谦《我爱你,却依然要看你走》[320K/MP3][88.65MB]