I have been using this code for a long time:

if (preg_match("/^слово/", $peremennaya)) { 

It checks for the presence of the word at the beginning of the $peremennaya variable. But how to make a simultaneous bulk check? That is, suppose I have to simultaneously check for the presence of the word "search" in the $get variable, as well as the word "forward" in the $santex variable and the word "price" in the $korzina variable.

I think we need to work with brackets "{" here. But I would like to hear the opinion of knowledgeable people ...

    2 answers 2

    Several preg_match in one condition

     if ( preg_match("/^поиск/", $get) && preg_match("/^вперед/", $santex) && preg_match("/^цена/", $korzina) ) { // Какой-то код... } 

      1) You do not check "availability", but "start from"
      2) As far as I know, what you want, as you suppose, I really do not advise it, but you can:

       preg_match( '/слово1[^\v]*\v[^\v]*слово2[^\v]*\v[^\v]*слово3/', join('\v', array( $var1, $var2, $var3) ) ); 

      \v - vertical tab

      • In any case, the presence is checked)) - nick777
      • Thanks, but I will use the KiTE variant, the code looks more neat there. Although, then I will look at the speed of execution, probably ... - nick777
      • No, not anyway. If you have a regular /^слово/ , then it will be found in the lines "слово №1" and "слово №2" and not in the - "первое слово" and "второе слово" . And if it is just /слово/ , then all 4th variants will do. - KiTE
      • @ nick777, I wrote in the answer - a mass check can only be done by sticking together strings, I did not consider the trivial options ... - timka_s