php - How to search for the backslash (\) mark and the zero (0) in MySQL? -
summary/background
i have tried make search engine can search characters in mysql. encounter question below:
- when try search backslash (\) mark, result unwanted. (the result shows many data don't contain backslash)
- when try search number 0 (0), result none no matter content is.
my try
i have tried describe problem. , below code.
<? $search="\\"; //the searching word. (here wanna search word backslash (\).) $link=mysql_connect("localhost","xxx","ooo"); mysql_select_db("xxx",$link); if($search){ $str="select xxx sheet xxx '%$search%'"; $list=mysql_query($str,$link); while(list($xxx)=mysql_fetch_row($list)){ echo $xxx."<br>"; } } mysql_close($link); ?>
the data in database
below data in database: (xxx field in datasheet sheet
)
+-------------------------------------------+ | xxx | +===========================================+ | happy % ^_^ | | hello! \hello\ | | /\?"' | | ~!@#$%^&*()_+|}{":?><`1234567890-=\][';/.,| | oh! god!!! | +-------------------------------------------+
logically speaking, php page should print out result of:
hello! \hello\ /\?"' ~!@#$%^&*()_+|}{":?><`1234567890-=\][';/.,
but result is:
happy % ^_^ ~!@#$%^&*()_+|}{":?><`1234567890-=\][';/.,
why happens that?
the similar question
how search slash (\) in mysql? , why escaping (\) not required (=) required?
you can change specifying escape character, in:
select * titles title 'test\\' escape '|'
in answerer proposed adding “escape '|'” in end of sql statement, whole problem doesn't solved. it's transferring same problem other character (|). there better way resolve problem?
as have figured other q&as backlash escape keyword expression. can use 3 (some suggested four) backslashes escape them.
i've tested expression like '%\\\%'
match input 'mom\dad'
Comments
Post a Comment