PHP.nl

stristr

stristr

Case-insensitive strstr

 **stristr** string $haystack string $needle bool $before_needle

Returns all of starting from and including the first occurrence of to the end. haystack``needle

haystackThe string to search in

needleThe string to search for.

before_needle If true, returns the part of the before the first occurrence of the (excluding needle). stristr``haystack``needle

and 

are examined in a case-insensitive manner. needle``haystack

Returns the matched substring. If is not found, returns false. needle

Voorbeeld: example

<?php
  $email = 'USER@EXAMPLE.com';
  echo stristr($email, 'e'), PHP_EOL; // outputs ER@EXAMPLE.com
  echo stristr($email, 'e', true), PHP_EOL; // outputs US
?>

Voorbeeld: Testing if a string is found or not

<?php
  $string = 'Hello World!';
  if (stristr($string, 'earth') === FALSE) {
    echo '"earth" not found in string';
  }
// outputs: "earth" not found in string
?>

strstr``strrchr``stripos``strpbrk``preg_match