Snippets

Elvis Morales print_yes_if_contains_string() corrected.

Created by Elvis Morales
<?php
// To return YES we need to use here the not identical operator (!==) instead of not equal as it was before (!=).
// As the code was before (strpos($haystack, $needle)  !=  false) it evaluates to FALSE so that's why the IF() condition is returning NO.

function print_yes_if_contains_string($haystack, $needle) {
 if (strpos($haystack, $needle)  !==  false) {
    echo 'yes';
  }
  else {
    echo 'no';
 }
}

$a = 'Boats are made of wood.';
$b = 'Boats';
print_yes_if_contains_string($a, $b);

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.