You can use str_ireplace()
if you want to replace the whole string or convert your LIKE-parameter to a regular expression and use preg_replace()
(don't forget to preg_quote()
the string, though).
Example using regular expressions:
$parts = explode('%', $likeQuery)
foreach ($parts as &$innerString) {
$innerParts = explode('_', $innerString);
foreach ($innerParts as &$part) {
$part = preg_quote($part, '/');
}
// always unset references when you're done with them
unset($part):
$innerString = implode('.', $innerString);
}
// always unset references when you're done with them
unset($innerString):
$regex = implode('.*?', $parts);
$transformedString = preg_replace("/$regex/", '<span>$0</span>', $stringToTransform);