easyquestions easyquestions - 15 days ago 8
PHP Question

Set 2 values in strpos?

I'm stuck on this:

I run quite a few

strpos
in my code, and all of them work with 1 value. But when I need to use 2 values, I cannot get the code working.

Here is the issue, this works with 1 value, but not 2:

<?php

$a = strtolower($title);

if (strpos($a, 'opel') !== false) {
echo '<h2>Why Opel?</h2>';
}

?>




But I cannot find the right code to work with for example 'opel' 'corsa'

Answer

Why not use a conjunction?

<?php
  $a = strtolower($title);
  if (strpos($a, 'opel') !== false && strpos($a, 'corsa') !== false) { 
    echo '<h2>Why Opel Corsa?</h2>';
  }
?>

Like this?