5만포인트 - 정규식 ㅠ..ㅠ... > 그누4 질문답변

그누4 질문답변

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

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 = "<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 과 공지사항은 따옴표가 없어야 되겠군요
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;
© SIRSOFT
현재 페이지 제일 처음으로