zblog补全图片地址php版
时间:2023年09月25日
/来源:网络
/编辑:佚名
在使用api接口的时候,会发现,有些程序的图片报错规则是只存路径,这个时候就需要一个函数来补全内容里图片的完整路径了。
点击复制代码 PHP
function ytecn_imgallpath($str, $type=0) {
$cfg_basehost='域名';
$data ='';
if(stripos($str, '<img') !== false){
$arr= preg_split('/(<img.*?>)/i', $str, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
foreach($arr as $k => $a){
if(substr($a, 0, 4) == '<img') {
$imgpath = array();
preg_match('/<img.*?src="(.*?)"/i', $a, $imgpath);
$imgpath = $imgpath[1];
if(substr($imgpath, 0, 4) !== 'http' && substr($imgpath, 0, 4) !== 'https'){
$imgpath = $cfg_basehost.$imgpath;
$pattern = '/<img(.*?)src="(.*?)"(.*?)>/i';
$replacement = '<img${1}src="'.$imgpath.'"${3}>';
$a = preg_replace($pattern, $replacement, $a);
}
}
$data .= $a;
}
}else{
$data = $str;
}
return 
点击复制代码 PHP
function ytecn_imgallpath($str, $type=0) {
$cfg_basehost='域名';
$data ='';
if(stripos($str, '<img') !== false){
$arr= preg_split('/(<img.*?>)/i', $str, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
foreach($arr as $k => $a){
if(substr($a, 0, 4) == '<img') {
$imgpath = array();
preg_match('/<img.*?src="(.*?)"/i', $a, $imgpath);
$imgpath = $imgpath[1];
if(substr($imgpath, 0, 4) !== 'http' && substr($imgpath, 0, 4) !== 'https'){
$imgpath = $cfg_basehost.$imgpath;
$pattern = '/<img(.*?)src="(.*?)"(.*?)>/i';
$replacement = '<img${1}src="'.$imgpath.'"${3}>';
$a = preg_replace($pattern, $replacement, $a);
}
}
$data .= $a;
}
}else{
$data = $str;
}
return 
新闻资讯 更多
热门文章
- 178Moban源码谈谈免费源码与收费源码的区别
- 2帝国CMS忘记后台登陆用户名、密码、认证码的解决方法
- 3帝国CMS(EmpireCMS) v7.5后台任意代码执行漏洞及具体修复方法
- 4帝国CMS和WordPress 哪个好?哪个适合建站?
- 5如何解决Discuz的密码错误次数过多请15分钟后登陆的问题
- 6帝国cms灵动标签取得内容和栏目链接地址
- 7emlog pro 注册码“开心”教程(如果有一天,emlog官方版 或者 emlog免费版 跑路了,那用户怎么办?)
- 8织梦CMS在nginx下设置伪静态方法(附nginx伪静态规则)
- 9帝国cms后台登录出现”您还未登录”怎么解决?
- 10帝国cms7.5忘记登录密码 和忘记登录认证码以及多次登录 失败被锁定解决办法