您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php给编辑器中的图片添加域名

2024/5/1 18:41:29发布30次查看
/** * 替换fckedit中的图片 添加域名 * @param string $content 要替换的内容 * @param string $strurl 内容中图片要加的域名 * @return string * @eg */ function replacepicurl($content = null, $strurl = null) { if ($strurl) { //提取图片路径的src的正则表达式 并把结果存入$matches中 preg_match_all("/<img(.*)src=\"([^\"]+)\"[^>]+>/isu",$content,$matches); $img = ""; if(!empty($matches)) { //注意,上面的正则表达式说明src的值是放在数组的第三个中 $img = $matches[2]; }else { $img = ""; } if (!empty($img)) { $patterns= array(); $replacements = array(); foreach($img as $imgitem){ $final_imgurl = $strurl.$imgitem; $replacements[] = $final_imgurl; $img_new = "/".preg_replace("/\//i","\/",$imgitem)."/"; $patterns[] = $img_new; } //让数组按照key来排序 ksort($patterns); ksort($replacements); //替换内容 $vote_content = preg_replace($patterns, $replacements, $content); return $vote_content; }else { return $content; } } else { return $content; } }
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product