人人商城函数之html_images()和html_to_images()图片URL处理
函数位置
ewei_shopv2/core/model/common.php
功能
图片URL路径处理
用法
html_images($detail = '', $enforceQiniu = false) html_to_images($detail = '')
示例
//写入数据库 $content['detail'] = m('common')->html_images($_GPC['detail']); //读取数据 $content['detail'] => m('common')->html_to_images($content['detail']);
函数源码
public function html_images($detail = '', $enforceQiniu = false){ $detail = htmlspecialchars_decode($detail); preg_match_all('/<img.*?src=[\\\\\'| \\"](.*?(?:[\\.gif|\\.jpg|\\.png|\\.jpeg]?))[\\\\\'|\\"].*?[\\/]?>/', $detail, $imgs); $images = array(); if (isset($imgs[1])) { foreach ($imgs[1] as $img) { $im = array('old' => $img, 'new' => save_media($img, $enforceQiniu)); $images[] = $im; } } foreach ($images as $img) { $detail = str_replace($img['old'], $img['new'], $detail); } return $detail; } public function html_to_images($detail = ''){ $detail = htmlspecialchars_decode($detail); preg_match_all('/<img.*?src=[\\\\\'| \\"](.*?(?:[\\.gif|\\.jpg|\\.png|\\.jpeg]?))[\\\\\'|\\"].*?[\\/]?>/', $detail, $imgs); $images = array(); if (isset($imgs[1])) { foreach ($imgs[1] as $img) { $im = array('old' => $img, 'new' => tomedia($img)); $images[] = $im; } } foreach ($images as $img) { $detail = str_replace($img['old'], $img['new'], $detail); } return $detail; }