php explode, foreign characters leak through

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gth759k
Forum Commoner
Posts: 76
Joined: Mon Jun 15, 2009 3:04 am

php explode, foreign characters leak through

Post by gth759k »

I have a simple search engine and I'm trying to detect certain words in a string with something like this:

Code: Select all

 
$sql = "SELECT * FROM table_links WHERE title like('%" . $search . "%')";
 
but somehow anything in the database that is a foreign character or html symbol like "»" seems to find its way into the results even if the title doesn't contain the $search phrase. Does anyone know a method to strip all those things from the text before it gets to my query? Any help would be appreciated. Thanks.
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: php explode, foreign characters leak through

Post by aceconcepts »

This is becauase the % wildcard matches a given pattern in a string. You have not specified that you don't want any receive any other characters that may be in a string.
Post Reply