I am trying to figure out why when I enter a dot (.) into my search, it highlights every single character of the search results (it wraps each character in a <span class="search-highlight"></span>) and it’s also only showing 3 tickets which is weird because all of them have at least one dot in them:

The query that does the actual searching (along with the variables) is:
$q = mysql_real_escape_string($_GET['q']);
$query = trim(strtoupper($q));
$query = htmlentities($query, ENT_QUOTES, "UTF-8");
$construct = $is_employee==false ? "user='$userid' AND" : "";
$tickets_result = mysql_query("SELECT `id`, `subject`, `message`, `timestamp`, `user` FROM `tickets` WHERE $construct (upper(subject) LIKE '%".$query."%' OR upper(message) LIKE '%".$query."%')") or trigger_error(mysql_error());
And my highlight class:
class highlight
{
public $output_text;
function __construct($text, $words) {
$split_words = explode(" ", $words);
foreach ($split_words as $word) {
$text = preg_replace("|($word)|Ui",
"<span class=\"search-highlight\">$1</span>",
$text);
}
$this->output_text = $text;
}
}
Does anyone know why or how a simple dot (.) would cause this and is it possible to fix?
Thanks for any help in advance.
Just gotta add an alternative to escaped regular expression search here:
Perhaps what you want is a non-regex replace?
https://www.php.net/str_replace
For an exact match, that makes the most sense to me…