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>";
|

댓글 5개

<?
$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;
http://opencode.co.kr/club/club_main.php?cb_id=cb_dkdlemd#

덕분에 작업을 끝냈어요. 감사드려요.
댓글을 작성하시려면 로그인이 필요합니다. 로그인

그누4 질문답변

그누보드4 관련 질문은 QA 로 이전됩니다. QA 그누보드4 바로가기 기존 게시물은 열람만 가능합니다.

+
제목 글쓴이 날짜 조회
15년 전 조회 1,249
15년 전 조회 1,513
15년 전 조회 1,003
15년 전 조회 1,405
15년 전 조회 1,531
15년 전 조회 1,163
15년 전 조회 873
15년 전 조회 891
15년 전 조회 2,367
15년 전 조회 1,781
15년 전 조회 1,121
15년 전 조회 936
15년 전 조회 936
15년 전 조회 1,676
15년 전 조회 1,027
15년 전 조회 1,416
15년 전 조회 1,354
15년 전 조회 1,620
15년 전 조회 1,049
15년 전 조회 1,265
🐛 버그신고