0

how can i convert this into an array? if someone searches 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!!

2 Answers 2

3
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.

Sign up to request clarification or add additional context in comments.

2 Comments

Maybe using in_array(strtolower($query), $bad_words) would be better? Cheers
@lunohodov yep, assuming no prior manipulation/validation has been done, that would be better
0

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';
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.