Bug in search.php (PHP problem, solution inside) [message #22202] |
Thu, 20 January 2005 09:41 |
devnull
Messages: 16 Registered: September 2004
Karma: 0
|
Junior Member |
|
|
Some people noticed SQL errors when searching for a number-only string. I traced the bug back to the function "text_to_worda" in search.php; it returns an empty array when $text contains only numbers, effectively leading to a SQL error in line 445, because $qr is empty.
The reason for that is the PHP function str_word_count in line 339. It handles numbers just like whitespace.
http://www.php.net/manual/en/function.str-word-count.php
To fix this, I replaced str_word_count with preg_replace. So far, the search works fine. However, a search containing a number won't return any matches (I guess they are not indexed). But at least the error message is gone.
Original line 339:
$t1 = array_unique(str_word_count(strip_tags(strtolower($text)), 1));
Replaced with:
$t1 = array_unique(preg_split("/\s+/", strip_tags(strtolower($text))));
I'm using FudForum 2.6.6 on Apache/2.0.46 with PHP 4.3.2 (Zend 1.3.0) using MySQL 11.18 Distrib 3.23.58.
|
|
|
|
|
|
|