1.

Solve : php sql string querying with wildcard?

Answer»

I currently have a php file that runs when users SUBMIT text in certain fields around my site. Right now, the file only looks for specifics words I enter into a table, and it only finds exact words. What I want to do is have the sql tring be able to USE wildcard values around the {invalid_word} tag so it can FIND and prevent a user from submitting text if a long word contains the text on my banned list. Like, if I banned the word hair, and someone tried using the word hairball, it would let them. This is what the current php file code is

Code: [Select]<?php
# **** FIND BAD WORDS INTO THE ENTERED STRING **** #
# param $str - TAKES an argument as an string
# match with database keywords
# return true if bad word found
# return FALSE if bad word not found

function findBadWords( $str ){

$return = false;

if( strlen( $str ) > 0 ) {
$sql  = "SELECT * FROM tbl_invalidunm WHERE MATCH (invalid_word) AGAINST (LCASE('".$str."') IN BOOLEAN MODE)";
$rs  = mysql_query( $sql ) or die( "Invalid query - ". mysql_error() );

if($rs){
$row_count  = mysql_num_rows($rs);

if( $row_count > 0 ) {
$return = true;
}
} // if
} // if
return $return;

} // end function 

?>



Discussion

No Comment Found