[정규식] 재미난? 정규식 Again #16 - 속성편
그누보드 안에 있는 여러가지 정규식중 thumbnail관련 정규식을 찾아 봅니다.
lib/common.lib.php
[code]
// 에디터 이미지 얻기
function get_editor_image($contents, $view=true)
{
if(!$contents)
return false;
// $contents 중 img 태그 추출
if ($view)
$pattern = "/<img([^>]*)>/iS";
else
$pattern = "/<img[^>]*src=[\'\"]?([^>\'\"]+[^>\'\"]+)[\'\"]?[^>]*>/i";
preg_match_all($pattern, $contents, $matchs);
return $matchs;
}
[/code]
각 게시판에 포함된 이미지 태그를
lib/thumbnail.lib.php 에서
get_list_thumbnail
get_view_thumbnail 중에서.
[code]
$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]);
[/code]
각 게시판 글에 포함 된 이미지 태그중에서 attribute를 뽑아내는 정규식입니다.
src, style, alt를 width, height는 style안에서 뽑아냅니다.
각각을 찾아서 이미지는 썸네일을 만들고 원본이미지를 포함해서 아래와 같은 링크를 만듭니다.
[code]
<a href="//sir.kr/bbs/view_image.php?bo_table=cm_pix&fn=654829463_lOzcMPxZ_5b0f91e594696877dc2950317a83deb4eef1e1cd.jpeg" target="_blank" class="view_image">
<img src="//sir.kr/data/file/cm_pix/thumb-654829463_lOzcMPxZ_5b0f91e594696877dc2950317a83deb4eef1e1cd_730x548.jpg" alt="">
</a>
[/code]
대략 아래와 같은 이미지를 찾아서 뽑아내는 것입니다.
지금까지 배운 내용으로 한 문장의 정규식이 필요합니다. (위의 정규식도 참조)
그룹네임은 $src, $style, $width, $height, $alt 입니다.
그런데 이것이 정규식으로 가능할까요?
-----------------------------------
<img style="width:100%; height:100%;display:none" src="http://test.com/data/editor/testimage.jpg" alt="test_img">
<img alt="test_img" style="width:100%; height:100%;display:none" src="http://test.com/data/editor/testimage.jpg">
<img src="http://test.com/data/editor/testimage.jpg" style="width:100%; height:100%;display:none" alt="test_img">
-----------------------------------
게시판 목록
퀴즈게시판
채택은 '좋아요'와 같습니다.
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 1026 |
|
7년 전 | 7149 | |
| 1025 |
|
7년 전 | 4163 | |
| 1024 |
|
7년 전 | 2131 | |
| 1023 | 7년 전 | 5025 | ||
| 1022 |
jamie50
|
7년 전 | 3885 | |
| 1021 |
|
7년 전 | 3725 | |
| 1020 |
jamie50
|
7년 전 | 5725 | |
| 1019 | 7년 전 | 7055 | ||
| 1018 | 7년 전 | 2999 | ||
| 1017 | 7년 전 | 6179 | ||
| 1016 | 7년 전 | 4780 | ||
| 1015 | 7년 전 | 2975 | ||
| 1014 |
|
7년 전 | 3116 | |
| 1013 | 7년 전 | 3863 | ||
| 1012 | 7년 전 | 2671 | ||
| 1011 |
|
7년 전 | 2323 | |
| 1010 | 7년 전 | 2240 | ||
| 1009 | 7년 전 | 2502 | ||
| 1008 | 7년 전 | 1966 | ||
| 1007 | 7년 전 | 2296 | ||
| 1006 |
|
7년 전 | 3919 | |
| 1005 | 7년 전 | 2106 | ||
| 1004 |
올드보이2
|
7년 전 | 2582 | |
| 1003 |
|
7년 전 | 1869 | |
| 1002 |
|
7년 전 | 2035 | |
| 1001 | 7년 전 | 2296 | ||
| 1000 |
TzM위드컴
|
7년 전 | 2253 | |
| 999 |
kjh38
|
7년 전 | 3108 | |
| 998 |
일본사설서버
|
7년 전 | 3207 | |
| 997 |
에스엠과호돌
|
7년 전 | 7475 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기