Extra Form
PHP PHP 7.2
CMS Rhymix 1.x

cond="!preg_match('/$widget_info->except_domain/', $val->link)"

 

 

위와 같은 코드로 스킨에서 특정 문자가 포함된 경우 제외를 해주려고 하는데요.

 

$widget_info->except_domain 에는 aaa|bbb 로 담겨서 잘 넘어옵니다.

 

그런데 필터가 안됩니다.

 

cond="!preg_match('/aaa|bbb/', $val->link)"

이렇게 하면 aaa,bbb 가 포함된 항목은 제외가 잘 됩니다.

 

 

  • profile
    preg_match('/$widget_info->except_domain/', $val->link)

    여기에서
    $widget_info->except_domain 이게 변수로 인식한게 아니라 이 문자열 그대로 인식한겁니다.


    preg_match(\"\/$widget_info->except_domain\/\", $val->link)
    혹은

    preg_match(\"/$widget_info->except_domain/\", $val->link)

    둘중에 하나 사용되는걸로 해보세요
  • profile profile
    두가지 모두 서버오류가 납니다.

    cond 안에 넣었습니다. if 문으로 바꿔서 시도해겠습니다.
  • profile profile

    if 문으로 해서 시도해봤는데 두가지 모두 서버에러가 나네요.

     

    2번째 것 

    ParseError #0 "syntax error, unexpected '"', expecting identifier (T_STRING)" in

  • profile
    <!--@if(!preg_match("/{$widget_info->except_domain}/", $val->link))-->

    위에 힌트 주신거로 이렇게 고치니 되는데 이게 제대로 한건지는 모르겠네요.
  • profile

    cond="!preg_match('/' . preg_quote($widget_info->except_domain, '/') . '/'), $val->link)"

     

    앞뒤의 슬래시를 별도의 문자열로 분리하고, 변수 내용도 제대로 escape 처리해 주셔야 합니다.

    정규식은 일반 문자열이나 쿼리문과는 또 다른 세상이라...

  • profile profile
    감사합니다. 이것도 킵해서 다른 곳에서 또 써먹어야 겠습니다.
  • profile profile
    이것도 서버 에러가 나네요.


    ParseError #0 "syntax error, unexpected ','" in
  • profile profile
    cond에서 안에 있는 내용이 좀 이상하게 작동하나봐요 템플릿에서 사용못하는..

    주석문으로 사용해야하나봐요...ㅠ
  • profile profile
    if 로 바꿔봐도 동일한 에러가 나요.
  • profile profile
    {@
    $bool = preg_match("/$widget_info->except_domain/", $val->link); // 중갈호 제거하세요
    }

    if($bool)

    써보세요
  • profile profile

    중괄호 없이 시도했을때 안되서 중괄호 넣고 되었거든요.

     

    <!--@if(!preg_match("/{$widget_info->except_domain}/", $val->link))-->


    요거 중괄호 없이 시도해 봤을때는 안되었고 중괄호 넣으니 됩니다.

  • profile profile
    죄송합니다. 괄호를 2개 열고 3개 닫았네요. ㅠ
    $val->link 바로 앞에 있는 괄호를 지우면 되겠습니다.
  • profile profile
    서버에러는 사라졌는데 필터링이 안되네요 ㅜㅡ
  • profile profile
    {@
    $bool = preg_match("/$widget_info->except_domain/", $val->link); // 중갈호 제거하세요
    }
    이거 시도해보신건가요?
  • profile profile

    중괄호 있어도 되서 따로 해보지는 않았습니다.

     

    $bool  변수에 담지 않았지만 이미 중괄호 없이 시도했을때 안되었구요.

  • profile profile

    {preg_quote($widget_info->except_domain, '/')}

    이렇게해서 출력해보니

    aaa\|bbb

    이렇게 찍히네요. \ 거 하나가 추가되서 문제가 생기나 봅니다.

     

     

    cond="!preg_match('/' . $widget_info->except_domain . '/', $val->link)"

     

    이렇게 하니 잘 됩니다.

  • profile
    근데 그냥 strpos 쓰면 안 되나요?
  • profile profile
    stops 필터할 단어 여러개를 쓰는 법이 어떻게 될까요??
    preg_match('/aaa|bbb/', $val->link) 이렇게 "|" 구분해서 필터링 하는게 있어서 이 함수를 사용했습니다.
  • profile profile

    아 댓글만 보다가 본문을 제대로 못봤네요;;;
    변수에 이미 정규표현식이 담긴 거군요