1000字范文,内容丰富有趣,学习的好帮手!
1000字范文 > php正则替换处理HTML页面办法php替换html页面

php正则替换处理HTML页面办法php替换html页面

时间:2022-06-18 13:00:38

相关推荐

php正则替换处理HTML页面办法php替换html页面

php教程|php手册

php,正则,HTML,字符串

php教程-php手册

php正则替换处理HTML页面的方法,php替换html页面

e4a手机强制上锁源码,mac vscode搭建,ubuntu mtk,tomcat jre环境,sqlite获取记录数,帝国cms7.5图片插件使用,前端移动端开发框架对比,爬虫查王者隐藏战绩,php 日期 函数,南京seo优化收费,视觉差网站原理,网页变灰代码,登录界面的html模板lzw

本文实例讲述了php正则替换处理HTML页面的方法。分享给大家供大家参考。具体如下:

tpshop分销源码,vscode怎么初始化一个项目,启动选项ubuntu,在线升级tomcat8,豆瓣fm爬虫,php 字母转16进制,铁门关seo网络营销渠道lzw

<?phpif(!defined(BASEPATH)) exit(No direct script access allowed); /** * HTML替换处理类,考虑如下几种替换 * 1. img src : /]+?)/i * 2. a href : /]+?)/i * 3. ifram.src : /]+?)/i * 4. frame src : /]+?)/i * 5. js : /window.open([( ]+?)([\\" ]+?)(.+?)([ )+?])/i * 6. css : /background(.+?)url([( ])([\\" ]+?)(.+?)([ )+?])/i */ class Myreplace { private $moudle_array = array(udata, data, result,dresult); private $content; private $relative_dirname; private $projectid; private $moudle; function __construct() { $this->CI = &get_instance (); } /** * 替换 * @param string $content HTML内容 * @param string $relative 相对路径 * @param int $projectid 项目id * @moudle string $moudle 模板标识: udata,tdata,tresult,dresult */ public function my_replace($content,$relative,$projectid,$moudle) { $this->content = $content; $this->relative_dirname = $relative; $this->projectid = $projectid; if(in_array(strtolower($moudle),$this->moudle_array)) $this->moudle = $moudle; else exit; switch($this->moudle) { case udata:$this->CI->load->model(mupload_data,model);break; case data:$this->CI->load->model( askdata,model);break; case result:$this->CI->load->model( askresult,model);break; case dresult:$this->CI->load->model(dmsresult,model);break; default:break; } $pattern = /]+?)/i; $content = preg_replace_callback( $pattern, array($this, image_replace) , $content ); $pattern = /]+?)/i; $content = preg_replace_callback( $pattern, array($this, html_replace) , $content ); $pattern = /]+?)/i; $content = preg_replace_callback( $pattern, array($this, iframe_replace) , $content ); $pattern = /]+?)/i; $content = preg_replace_callback( $pattern, array($this, frame_replace), $content ); $pattern = /window.open([( ]+?)([\\" ]+?)(.+?)([ )]+?)/i; $content = preg_replace_callback( $pattern, array($this, js_replace), $content ); $pattern = /background(.+?)url([( ])([\\" ]+?)(.+?)([ )+?])/i; $content = preg_replace_callback( $pattern, array($this, css_replace), $content); return $content; } private function image_replace($matches) { if(count($matches) relative_dirname; for($i=0; $iCI->model->get_id_by_path_and_project($relativepath,$this->projectid); //输出 if( !empty($image_id) ) { if($this->moudle == dresult) {return "CI->config->item("base_url")."cdms/".$this->moudle."/readpic/$image_id?pid=".$this->projectid .$matches[2]. $matches[4]; } else {return "CI->config->item("base_url")."cdms/".$this->moudle."/picfile/$image_id?pid=".$this->projectid .$matches[2]. $matches[4]; } } else { return "<img".$matches[1]."src=".$matches[2].$matches[3].$matches[2].$matches[4]; } } private function html_replace( $matches ) { if(count($matches) relative_dirname; for($i=0; $iCI->model->get_id_by_path_and_project($relativepath,$this->projectid); //输出 if( !empty($txtfile_id ) ) { if($this->moudle == dresult) {return "CI->config->item("base_url")."cdms/".$this->moudle."/readfile/$txtfile_id?pid=".$this->projectid .$matches[2].$matches[4]; } else {return "CI->config->item("base_url")."cdms/".$this->moudle."/txtfile/$txtfile_id?pid=".$this->projectid .$matches[2].$matches[4]; } } else { return "0)$matches[3] = substr($matches[3],0,strrpos($matches[3],#)); //获取html的id $parent_dir_num = substr_count( $matches[3], ../); $relative_dirname = $this->relative_dirname; for($i=0; $iCI->model->get_id_by_path_and_project($relativepath,$this->projectid); //输出 if( !empty($txtfile_id ) ) { if($this->moudle == dresult) { return "CI->config->item("base_url")."cdms/".$this->moudle."/readfile/$txtfile_id?pid=".$this->projectid .$matches[2].$matches[4]; } else {return "CI->config->item("base_url")."cdms/".$this->moudle."/txtfile/$txtfile_id?pid=".$this->projectid .$matches[2].$matches[4]; } } else { return "<iframe".$matches[1]."src=".$matches[2].$matches[3].$matches[2].$matches[4]; } } private function frame_replace( $matches ) {if(count($matches) 0)$matches[3] = substr($matches[3],0,strrpos($matches[3],#)); //获取html的id $parent_dir_num = substr_count( $matches[3], ../); $relative_dirname = $this->relative_dirname; for($i=0; $iCI->model->get_id_by_path_and_project($relativepath,$this->projectid); //输出 if( !empty($txtfile_id ) ) { if($this->moudle == dresult) {return "CI->config->item("base_url")."cdms/".$this->moudle."/readfile/$txtfile_id?pid=".$this->projectid.$matches[2].$matches[4]; } else {return "CI->config->item("base_url")."cdms/".$this->moudle."/txtfile/$txtfile_id?pid=".$this->projectid.$matches[2].$matches[4]; } } else { return "<frame".$matches[1]."src=".$matches[2].$matches[3].$matches[2].$matches[4]; } } private function js_replace( $matches ){ if(count($matches) < 4) return \; if( empty($matches[3]) ) return \; //处理链接 $arr_html = split(,,$matches[3]); $href = $arr_html[0]; $other = \; for($i=0; $i0)return "window.open".$matches[1].$matches[2].$matches[3].$matches[4];; //获取html的id $parent_dir_num = substr_count( $href, ../); $relative_dirname = $this->relative_dirname; for($i=0; $iCI->model->get_id_by_path_and_project($relativepath,$this->projectid); //输出 if( !empty($txtfile_id ) ) { if($this->moudle == dresult) {return "window.open".$matches[1].$matches[2].$this->CI->config->item("base_url")."cdms/".$this->moudle."/readfile/$txtfile_id?pid=".$this->projectid.$matches[2].,.$other.$matches[4]; } else {return "window.open".$matches[1].$matches[2].$this->CI->config->item("base_url")."cdms/".$this->moudle."/txtfile/$txtfile_id?pid=".$this->projectid.$matches[2].,.$other.$matches[4]; } } else { return "window.open".$matches[1].$matches[2].$matches[3].$matches[4]; } } private function css_replace( $matches ) { if(count($matches) relative_dirname; for($i=0; $iCI->model->get_id_by_path_and_project($relativepath,$this->projectid); //输出 if( !empty($image_id) ) { if($this->moudle == dresult) {return "background".$matches[1]."url".$matches[2].$matches[3].$this->CI->config->item("base_url")."cdms/".$this->moudle."/readpic/$image_id?pid=".$this->projectid .$matches[3]. $matches[5]; } else {return "background".$matches[1]."url".$matches[2].$matches[3].$this->CI->config->item("base_url")."cdms/".$this->moudle."/picfile/$image_id?pid=".$this->projectid .$matches[3]. $matches[5]; } } else { return "background".$matches[1]."url".$matches[2].$matches[3].$matches[4].$matches[3].$matches[5]; } } }/* End of Myreplace.php *//* Location: /application/libraries/Myreplace.php */

刀了个塔网络手游源码,vscode设置外观,ubuntu缺点,tomcat 安全项,sqlite删除重复数据,jquery tab插件 关闭,前端静态资源部署框架,怎样驱走家里的爬虫虫,php 静态html,seo新人培训分类,外贸网站 php,网页图文编辑工具,织梦模板修改视频教程lzw

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。