I am trying to come up with a simplistic search that will permit a user to insert multiple values separated by common words such as 'and' and 'or'. I have the following, but I can't figure out how to stop the results from including matches to the space between the values. I know it's going to be simple, but it's evading me at the moment. Suggestions please?
[code=php]$term = mysqli_real_escape_string($con, $_GET['search']);
$commonWords = array('and', 'or');
foreach($commonWords as $word)
{
$term = preg_replace("/\b$word\b/i",'',$term);
}
$term = explode(" ", ($term));
$sql = "SELECT * FROM content WHERE (title LIKE '%" . $term[0] . "%' OR subtitle LIKE '%" . $term[0] . "%' OR content LIKE '%" . $term[0] . "%')";
for($i=1; $i < count($term); $i++)
{
$sql = $sql . " OR (title LIKE '%" . $term[$i] . "%' OR subtitle LIKE '%" . $term[$i] . "%' OR content LIKE '%" . $term[$i] . "%')";
}[/code]