채택완료

else if 문의드립니다.

2017-12-20 (수) 21:37:35 2,299
Copy
else if( strpos($content,  "단어") !== false )

{

echo <<< EOD

    {

        "message": {

            "text": "내용"

        }

    }    

EOD;

}

else if( strpos($content,  "단어") !== false ) 여기에서 여러단어를 사용하고 싶은데요

예를들면

else if( strpos($content,  "단어","단어2",단어3","단어4") !== false )

이렇게 사용할려면 어떻게 해야되나요?

|

답변 1개 / 댓글 5개

채택된 답변
+20 포인트

function strpos_arr($content, $word) { 
    return preg_match( "/$word/", $content );
}

echo strpos_arr($content, '단어1|단어2');

답변에 대한 댓글 5개

2017-12-20 (수) 22:05:34
function strpos_arr($content, $word) {
return preg_match( "/$word/", $content );
}

echo strpos_arr($content, '단어|단어2ㅣ단어3');


{

echo <<< EOD

{

"message": {

"text": "내용"

}

}

EOD;

이렇게 하면되는건가요? 에러가나는거같에서요
// if문 밖에 위치
function strpos_arr($content, $word) {
return preg_match( "/$word/", $content );
}

else if ( strpos_arr($content, '단어1|단어2') )
2017-12-20 (수) 23:15:11
else if( $content == "시작")

{

echo <<< EOD

{

"message": {

"text": "인사말"

}

}

EOD;

}

function strpos($content, $word) {
return preg_match( "/$word/", $content );
}

else if ( strpos($content, '단어1|단어2') !== false )
{
echo <<< EOD

{

"message": {

"text": "내용"

}

}

EOD;

}

이렇게 적었는데요 에러가 발생하는데요?
이게 맞는거죠?
함수로 만들어 드렸는데 적용을 어려워 하시네요.

else if( strpos($content, "단어") !== false )
=>
else if ( preg_match('/단어1|단어2/', $content) )
2017-12-20 (수) 23:48:50
아감사합니다?

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