The problem with your code is that when you replace space with %%
, you get a search like:
WHERE title like '%AB%%Zilva%'
but this won't match when the title is A B Zilva
. You need to remove spaces from both the search string and the column in the database. Do it like this:
$searchp = str_replace(' ', '', $searchp);
and then change the SQL to:
WHERE REPLACE(title, ' ', '') LIKE '%$searchp%'
For the Javascript highlighting, I think you need to do this:
var term = this.element.val().replace(/ /g, '').replace(/.(?=.)/g, '$& *'),
This will create a regular expression that allows for spaces between any of the characters in the search string.