[정규식] 재미난? 정규식 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">
-----------------------------------
게시판 목록
퀴즈게시판
채택은 '좋아요'와 같습니다.
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 1266 |
언제마스터합니까
|
5년 전 | 1516 | |
| 1265 |
언제마스터합니까
|
5년 전 | 2278 | |
| 1264 |
|
5년 전 | 1335 | |
| 1263 |
명왕이인우
|
5년 전 | 1922 | |
| 1262 | 5년 전 | 1352 | ||
| 1261 |
|
5년 전 | 1235 | |
| 1260 | 5년 전 | 1513 | ||
| 1259 | 5년 전 | 1930 | ||
| 1258 |
|
5년 전 | 1428 | |
| 1257 | 5년 전 | 2396 | ||
| 1256 | 5년 전 | 1638 | ||
| 1255 |
|
5년 전 | 1832 | |
| 1254 |
별지기천사
|
5년 전 | 1605 | |
| 1253 |
|
5년 전 | 1480 | |
| 1252 | 5년 전 | 1395 | ||
| 1251 | 5년 전 | 2242 | ||
| 1250 |
|
5년 전 | 1423 | |
| 1249 |
|
5년 전 | 1636 | |
| 1248 |
|
5년 전 | 4441 | |
| 1247 | 5년 전 | 1350 | ||
| 1246 | 5년 전 | 1760 | ||
| 1245 | 5년 전 | 2268 | ||
| 1244 | 5년 전 | 1522 | ||
| 1243 | 5년 전 | 2092 | ||
| 1242 | 5년 전 | 1153 | ||
| 1241 | 5년 전 | 2286 | ||
| 1240 | 5년 전 | 2558 | ||
| 1239 |
냥냥이입니당
|
5년 전 | 2337 | |
| 1238 | 5년 전 | 1883 | ||
| 1237 |
backstracker
|
5년 전 | 2826 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기