开发者

Simple PHP Array Problem - IF EXIT

how can i convert this into an array? if someone se开发者_高级运维arches for "lo" he gets the text "no query", but how can i do this for more words? i tried it with array('1','2')..

if ($query == 'lo')
{
  exit ('No Query.');
}

i want something like this

if ($query == 'lo', 'mip', 'get')
{
  exit ('No Query.');
}

so, if someone types mip he gets the message.. thank you!!


if ($query == 'lo' || $query == 'mip' || $query == 'get') {
    exit('No query');
}

Or if you might want to add many strings to check for, try using an array.

$bad_words = array('lo', 'mip', 'get', ... );
if (in_array($query, $bad_words)) {
    exit('No query');
}

Then adding new 'bad words' is as easy as adding them to the array.


Your array should look like this:

$array = array('lo', 'mip', 'get');

Now Search

if (in_array('mip', $array))
{
  echo 'We have a match';
}
else
{
  echo 'No match';
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜