게시물에 있는 첫번째 이미지 가져오려면 어떻게해야될까요?
본문
$jw_img_url = G5_DATA_URL.'/file/'.$bo_table."/".$view['file'][0]['file'];
답변 1
// $contents 중 img 태그 추출
$matches = get_editor_image($contents, true);
if(empty($matches))
return $contents;
for($i=0; $i<count($matches[1]); $i++) {
$img = $matches[1][$i];
preg_match("/src=[\'\"]?([^>\'\"]+[^>\'\"]+)/i", $img, $m);
$src = $m[1];
preg_match("/style=[\"\']?([^\"\'>]+)/i", $img, $m);
$style = $m[1];
preg_match("/width:\s*(\d+)px/", $style, $m);
$width = $m[1];
preg_match("/height:\s*(\d+)px/", $style, $m);
$height = $m[1];
preg_match("/alt=[\"\']?([^\"\']*)[\"\']?/", $img, $m);
$alt = get_text($m[1]);
// 이미지 path 구함
$p = parse_url($src);
if(strpos($p['path'], '/'.G5_DATA_DIR.'/') != 0)
$data_path = preg_replace('/^\/.*\/'.G5_DATA_DIR.'/', '/'.G5_DATA_DIR, $p['path']);
else
$data_path = $p['path'];
$srcfile = G5_PATH.$data_path;
}