Fuzzy search within a string

Hi,

I’m trying to do a fuzzy search within a string. Is it possible using stristr? Or would preg_match be a better way to do it? By fuzzy I mean the search term could be more than one word and the words weren’t together in the string but were found somewhere in the string it would return true.

I hope that makes sense


<?php

$the_string = "They're my everyday balloons";
$searchTerm ="my balloons";

if (stristr($the_string, $searchTerm){
   echo "A match was found";
}

?>


Thanks!

Sure. :slight_smile:


function fuzzy_search($needles, $haystack){
  foreach(explode(' ', $needles) as $needle){
    if(stristr($haystack, $needle)){
      return true;
    }
  }
  return false;
}


if(fuzzy_search('my balloons', 'my parents like balloons')){
  #found
}

Cheers Anthony that’s exactly what I was after! :slight_smile: