Using the string functions

Code that determines if a string contains another string

<?php
  $name = 'John F. Kennedy Jr.';
  $contains = str_contains($name, '.';            // TRUE
  $starts_with = str_starts_with($name, 'Mr.');   // FALSE
  $ends_with = str_ends_with($name, 'Jr.';        // TRUE
?>

An if statement that does the same thing

<?php
  $name = 'Ray Harris';
  if (str_contains($name, ' ')) { ... }
?>

Back