Jump to content

sql string querying with wildcard


toonz

Recommended Posts

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

 

<?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 

?>

 

 

Thanks in advance for your help

Link to comment
https://forums.phpfreaks.com/topic/174523-sql-string-querying-with-wildcard/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.