zoukankan      html  css  js  c++  java
  • 获取Ueditor里面的图片列表,地址绝对化

    /**
         * 内容中图片地址转成绝对地址
         * @param $content
         * @return mixed
         */
        private function imgUrl($content)
        {
            preg_match_all('/<img(.*)src="([^"]+)"[^>]+>/isU', $content, $matches);
            $vote_content = $content;
            $img = '';
            $imgDiv = '';
            if (!empty($matches)) {
                //注意,上面的正则表达式说明src的值是放在数组的第三个中
                $img = $matches[2];
                $imgDiv = $matches[0];
            } else {
                $img = '';
                $imgDiv = '';
            }
            if (!empty($img)) {
                $img_url = asset('');
                $patterns = array();
                $replacements = array();
                foreach ($img as $imgItem) {
                    $final_imgUrl = $img_url . $imgItem;
                    //获取文本中的所有图片
                    $this->imgString[] = $final_imgUrl;
                    $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;

        }

  • 相关阅读:
    Cesium中的坐标系及转换
    Cesium Workshop
    window.postMessage 跨窗口,跨iframe javascript 通信
    VUE课程参考---7、跑马灯效果
    VUE课程---9、事件绑定v-on
    VUE课程---8、属性绑定v-bind
    VUE课程---7、解决插值表达式闪烁问题
    小谈chrome调试命令:console.log的使用
    Hadoop平台配置总结
    hadoop 关闭进程时报错no 进程 to stop
  • 原文地址:https://www.cnblogs.com/jhy-ocean/p/7483082.html
Copyright © 2011-2022 走看看