{
    分享网正式开通,我们为大家提供免费资源,欢迎大家踊跃投稿!

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

正则表达式替换图片格式

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改造了,然后怎么用就看大家自己了。


资源均来自第三方,谨慎下载,前往第三方网站下载


米微资源分享网 , 版权所有丨本站资源仅限于学习研究,严禁从事商业或者非法活动!丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:百度MIP改造常用正则表达式
喜欢 ()分享 (0)