5만포인트 - 정규식 ㅠ..ㅠ... 정보
5만포인트 - 정규식 ㅠ..ㅠ...본문
머리가 너무 아퍼서, 포기하구 도움을 요청해요.
아래처럼 $text 변수에 간단한 형식의 html과 그누의 최신글 함수를 넣었어요.
1. <?=latest(변수값)?>와 같은 형식의 패턴을 찾아서
2. 변수값들의 목록을 구하고
3. latest("basic", "공지사항", 10, 40)의 결과값으로 패턴을 교체하는 겁니다.
정규식 내공이 0이라서, 봐도 봐도 답이 없네요. ㅠ..ㅠ...
$text = "<br>fff<hr><table><tr><td><?=latest("basic", "공지사항", 10, 40);?></td></tr></table>";
아래처럼 $text 변수에 간단한 형식의 html과 그누의 최신글 함수를 넣었어요.
1. <?=latest(변수값)?>와 같은 형식의 패턴을 찾아서
2. 변수값들의 목록을 구하고
3. latest("basic", "공지사항", 10, 40)의 결과값으로 패턴을 교체하는 겁니다.
정규식 내공이 0이라서, 봐도 봐도 답이 없네요. ㅠ..ㅠ...
$text = "<br>fff<hr><table><tr><td><?=latest("basic", "공지사항", 10, 40);?></td></tr></table>";
댓글 전체
<?
$text = "<br>fff<hr><table><tr><td><?=latest(basic, 공지사항, 10, 40);?></td></tr></table>";
preg_match("|<\?=latest\(([^)]+)\);\?>|",$text, $tmp);
list($skin,$title, $line,$subj_len)=explode(",",$tmp[1]);
//테스트용 latest
function latest($skin,$title, $line,$subj_len){
return "$skin,$title, $line,$subj_len";
}
?>
<?=latest($skin,$title, $line,$subj_len);?>
위와 같이 되겠습니다
보시는 바와 같이 basic 과 공지사항은 따옴표가 없어야 되겠군요
$text = "<br>fff<hr><table><tr><td><?=latest(basic, 공지사항, 10, 40);?></td></tr></table>";
preg_match("|<\?=latest\(([^)]+)\);\?>|",$text, $tmp);
list($skin,$title, $line,$subj_len)=explode(",",$tmp[1]);
//테스트용 latest
function latest($skin,$title, $line,$subj_len){
return "$skin,$title, $line,$subj_len";
}
?>
<?=latest($skin,$title, $line,$subj_len);?>
위와 같이 되겠습니다
보시는 바와 같이 basic 과 공지사항은 따옴표가 없어야 되겠군요
아~ 이렇게 간단하게...ㅠ..ㅠ...
저는 몇십줄 하다가 욱~하고 지웠어요.
그런데, 이런게 여러개 있는거는 어떻게 찾아야 하나요???
저는 몇십줄 하다가 욱~하고 지웠어요.
그런데, 이런게 여러개 있는거는 어떻게 찾아야 하나요???
preg_match_all()인가 있습니다.
call_Back이 심플하네요.
$latest = stripslashes($cb[cb_latest_text]);
//http://kr.php.net/manual/en/function.preg-replace-callback.php
// http://sir.co.kr/bbs/board.php?bo_table=g4_qa&wr_id=152310
function replace_latest($matches) {
global $cb;
$latest_match = $matches[1];
list($skin,$title, $line,$subj_len)=explode(",",$latest_match);
$latest_data = cb_latest($skin, $cb[cb_id], $title, $line, $subj_length);
return $latest_data;
}
$pattern = "|<\?=cb_latest\(([^)]+)\);\?>|";
$new_latest = preg_replace_callback($pattern, "replace_latest", $latest);
echo $new_latest;
$latest = stripslashes($cb[cb_latest_text]);
//http://kr.php.net/manual/en/function.preg-replace-callback.php
// http://sir.co.kr/bbs/board.php?bo_table=g4_qa&wr_id=152310
function replace_latest($matches) {
global $cb;
$latest_match = $matches[1];
list($skin,$title, $line,$subj_len)=explode(",",$latest_match);
$latest_data = cb_latest($skin, $cb[cb_id], $title, $line, $subj_length);
return $latest_data;
}
$pattern = "|<\?=cb_latest\(([^)]+)\);\?>|";
$new_latest = preg_replace_callback($pattern, "replace_latest", $latest);
echo $new_latest;