Heim > php教程 > php手册 > php给编辑器中的图片添加域名

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Freigeben: 2016-06-13 10:42:52
Original
984 Leute haben es durchsucht

/** 
 * 替换fckedit中的图片 添加域名 
 * @param  string $content 要替换的内容 
 * @param  string $strUrl 内容中图片要加的域名 
 * @return string  
 * @eg  
 */ 
function replacePicUrl($content = null, $strUrl = null) {  
    if ($strUrl) {  
        //提取图片路径的src的正则表达式 并把结果存入$matches中    
        preg_match_all("/php给编辑器中的图片添加域名]+>/isU",$content,$matches);  
        $img = "";    
        if(!emptyempty($matches)) {    
        //注意,上面的正则表达式说明src的值是放在数组的第三个中    
        $img = $matches[2];    
        }else {    
           $img = "";    
        }  
          if (!emptyempty($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;  
    }  
}

Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Aktuelle Ausgaben
PHP-Datenerfassung?
Aus 1970-01-01 08:00:00
0
0
0
PHP-Erweiterung intl
Aus 1970-01-01 08:00:00
0
0
0
Wie man PHP gut lernt
Aus 1970-01-01 08:00:00
0
0
0
Mehrere PHP-Versionen
Aus 1970-01-01 08:00:00
0
0
0
Beliebte Empfehlungen
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage