using special characters in a php script

I need to write a query in a php script that using LIKE what do I need to add to specail chars such as % for it to work?
$query ="SELECT * FROM table WHERE field LIKE ' ". %$name % . ' " ;

Thank you.
Nura111Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Lukasz ChmielewskiConnect With a Mentor Commented:
Try to use double %% sign
0
 
Lukasz ChmielewskiCommented:
$query ="SELECT * FROM table WHERE field LIKE '%% ".$name."'%%" ;
0
 
Ray PaseurCommented:
Not sure I am reading the question the same way as Roads_Roads.

If you want to use wild-card matching, you use the LIKE and you use a string with a percent sign to match wild card strings.
http://dev.mysql.com/doc/refman/5.0/en/string-comparison-functions.html

Note that % matches any number of characters, even zero characters.  Underscore matches one character.

To test for literal instances of a wildcard character, precede it by the escape character. If you do not specify the ESCAPE character, “\” is assumed.

HTH, ~Ray
0
 
mansooralia_yahooCommented:
if you want to search these special characters [%_]  use slash to include them literally
0
 
Mostafa_BZConnect With a Mentor Commented:
f you want to search these special characters without any problem use the following:
 
$search_word = '%text%';
$search_word = addslashes($search_word);
$search_word = htmlentities($search_word,ENT_NOQUOTES,'utf-8');
$search_word = "%".$search_word."%";
$query ="SELECT * FROM table WHERE field LIKE '".$search_word."'";

Open in new window

0
All Courses

From novice to tech pro — start learning today.