채택완료

정규식 질문 드립니다.

2019-06-25 (화) 11:23:08 2,589

안녕하세요?

g5_menu에 있는 me_link에서 bo_table 값만 가져 오고 싶은데

정규식 어렵네요...

$test = "http://127.0.0.1/~gnuboard/bbs/board.php?bo_table=event";

여기서 뒤에 event 만 가져오려면 정규식을 어떻게 짜야 할까요?

|

답변 4개 / 댓글 2개

채택된 답변
+20 포인트

어차피 url이라면 쉽게가시죠!


function get_bo_table($url){
    $parsed_url = parse_url($url);
    parse_str($parsed_url['query'], $output);
    return $output['bo_table']?$output['bo_table']:'';
}
$url = "http://127.0.0.1/~gnuboard/bbs/board.php?bo_table=event";
echo get_bo_table($url);

답변에 대한 댓글 1개

감사합니다 ^^
2019-06-25 (화) 22:35:25

저도 배우고 갑니다

$test = "http://127.0.0.1/~gnuboard/bbs/board.php?bo_table=event";

$pattern = "#bo_table=(.+)#i";

preg_match($pattern, $test, $match);
echo $match[1];

걍 $bo_table  또는 $_GET[bo_table ]

답변에 대한 댓글 1개

주소창에 있으면 그렇게 하면 되는데 변수에 있는것도 그렇데 되나요?

답변을 작성하려면 로그인이 필요합니다.