PHP
(함수-정규식) preg_match() - 에디터 콘텐츠 이미지찾기
승철
2013. 11. 27. 16:54
* 적용함수 * preg_match_all() * preg_match() * getimagesize() * filesize() function appImages($text){ global $_fileDir; global $_fileUrl; $img1 = array(); $img_cnt = preg_match_all("/<img[^>]*src=[\"']?([^>\"']+)[\"']?[^>]*>/i", $text, $match); //이미지파일 html 추출 if($img_cnt > 0) { for ($i=0; $i<$img_cnt; $i++) { $img1[] = $match[0][$i]; $img2[] = $match[1][$i]; } } $html = ""; if(count($img1) > 1){ for($i=0; $i<@count($img1); $i++) { $img1_text = $img1[$i]; preg_match("/<img[^>]*src=[\"']?([^>\"']+)[\"']?[^>]*>/i", $img1_text, $match_url); //이미지 경로만 추출 $img_url = trim($match_url[1]); //$img_dir = str_replace("http://file.domain.com/", "/home/domain/file/", $img_url); $img_dir = str_replace($_fileUrl, $_fileDir, $img_url); if(is_file($img_dir)) { $img_size = getimagesize($img_dir); $file_size = filesize($img_dir); $file_size = $file_size/1024; $html .= "삭제 "; $html .= "보기 "; $html .= "".$img_url." "; $html .= "(".$file_size."KB, ".$img_size[0]."x".$img_size[1].") "; } } } return $html; }