js教程

百度MIP改造常用正则表达式

我的站长站 2019-05-18 人阅读

正则表达式替换图片格式

function NewsTextReplace($add){
    $add['newstext'] = preg_replace('/<img.*?src="(.*?)".*?>/is', '<mip-img alt="" src="$1"></mip-img>', stripslashes($add['newstext']));
    $add['newstext'] = preg_replace('/<a.*?href="(.*?)".*?</a>/is', '<a data-type="mip" data-title="' . $add['title'] . '" href="$1"></a>', $add['newstext']);
    $add['newstext'] = addslashes($add['newstext']);
    return $add;
}

正则表达式替换链接格式

function get_img_thumb_url($data){ 
    $data = str_replace('<a', '<mip-link', $data);
    $data = preg_replace('/ target=".*?"/', '',$data);//移除target
    $data = preg_replace('/ style=".*?"/', '',$data);//移除style
    $data = preg_replace('/ class=".*?"/', '',$data);//移除class
    $data = str_replace('</a>', '</mip-link>', $data);
    return $data;  
}

正则表达式删除无用代码

function get_img_thumb_url($data){ 
    $data = str_replace('onclick=/"zoom(this, this.src, 0, 0, 0)/" ','',$data);
    $data = str_replace('class=/"zoom/"','',$data);
    $data = str_replace('onmouseover=/"img_onmouseoverfunc(this)/"','',$data);
    $data = str_replace('onload=/"thumbImg(this)/" ','',$data);
    $data = str_replace('border=/"0/"','',$data);
    $data = str_replace('alt=""','',$data);
    $data = str_replace('<br />','<br>',$data);
    return $data;  
}

百度MIP改造最难的就是正则表达式了,以上正则表达式基本够用百度MIP改造了,然后怎么用就看大家自己了。

相关推荐
  • 正则表达式
  • Regulex在线正则表达式可视化测试工具
    Regulex在线正则表达式可视化测试工具

    Regulex跟其他的正则表达式工具不同的是,他可以直接以图片的形式显示出正则表达式匹配的流程和结果,非常方便的帮助程序员正确的书写正则表达式规则。例如我们输入(d{100}|d{10})w{2}正则,可视化...

    在线工具 1212 4年前
  • 帝国CMS百度MIP改造newstext正则表达式

    本教程主要功能就是把编辑器内的img a标签等替换为mip标准格式1、打开/e/class/userfun.php添加处理函数:function NewsTextReplace($add){ $add[&#39;newstext&#39;] = preg_replace(&#39;/<img.*?src="(.*?)".*?>/is&#39;, &#39;<mip-img alt=""...

    帝国cms教程 198 4年前
  • 百度MIP改造常用正则表达式

    正则表达式替换图片格式function NewsTextReplace($add){ $add[&#39;newstext&#39;] = preg_replace(&#39;/<img.*?src="(.*?)".*?>/is&#39;, &#39;<mip-img alt="" src="$1"></mip-img>&#39;, stripslashes...

    js教程 122 4年前
最新更新
  • js截取字符串教程

    slice()方法接受两个参数,起始索引和结束索引(可选)。它返回从起始索引到结束索引(不包括结束索引)之间的子字符...

    js教程 2个月前
  • find findIndex indexOf索引选择器使用方法

    find使用方法find方法是ES6引入的一种数组方法,可以用来查找数组中符合条件的元素。语法是:array.find(callba...

    js教程 3个月前
  • js复制网页内容教程

    Async Clipboard API方法HTML5新增的方法,无需引入第三方插件,直接就可以复制内容。低版本的浏览器可能会不兼...

    js教程 3个月前
  • js获取字符长度函数分享

    js获取字符长度函数function objLen(str) { if (str == null) return 0; if (typeof str != "string") { ...

    js教程 3个月前
  • 网站LED跑马灯效果广告代码

    网站可以看到很多的论坛网站都会用到这种网站LED跑马灯效果,这种效果实现也很简单,分享给大家。LED跑马灯效果...

    js教程 4个月前