게시물에 있는 첫번째 이미지 가져오려면 어떻게해야될까요?

게시물에 있는 첫번째 이미지 가져오려면 어떻게해야될까요?

QA

게시물에 있는 첫번째 이미지 가져오려면 어떻게해야될까요?

답변 1

본문

$jw_img_url = G5_DATA_URL.'/file/'.$bo_table."/".$view['file'][0]['file'];

현재 이런식으로 가지고오고있는데
링크이미지던 editor에서 첨부된 이미지던

jw_img_url  변수로 
첫번째에잇는 이미지를 가져오려면 어떻게해야될까요
저렇게하면 파일로 첨부된 이미지만 가져와서요 ㅜㅜ

이 질문에 댓글 쓰기 :

답변 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;

}

 

답변을 작성하시기 전에 로그인 해주세요.
QA 내용 검색
질문등록
전체 10
© SIRSOFT
현재 페이지 제일 처음으로