How to scan an array of a variable and compare it to another variable? [duplicate]

0

I have the code below that works fine, but I would like the information in strings to be picked up in an array, for example:

$array = array('cia','Cia','dia','Dia','hoje');

and check if one of these words is in the text variable.

Does anyone know how to do this?

$texto = $_REQUEST['text'];
    if((strpos($texto,'cia')!==false || strpos($texto,'Cia')!==false || strpos($texto,'dia')!==false || strpos($texto,'prod')!==false) || (strpos($texto,'daily')!==false || strpos($texto,'Daily')!==false || strpos($texto,'prod')!==false) || strpos($texto,'hoje')!==false || strpos($texto,'produ%C3%A7%C3%A3o%20di%C3%A1ria')!==false) {

     //pega a pagina que quero redirecionar
}
    
asked by anonymous 03.05.2016 / 20:01

1 answer

1

Change these OUs by using the in_array() function, it uses two arguments, the first is the string to be fetched and the second the items to be compared.

<?php
$texto = $_REQUEST['text'];
$array = array('cia','Cia','dia','Dia','hoje');

if(in_array($texto, $array)){
   echo 'texto encontrado no array';
}
    
03.05.2016 / 20:04