how to remove a single quote ' in the search string...since it would generate an error if single quote is included...

example, in an input box, the search string below are typed

'computer
computer'
'c'o'm'p'u't'e'r


if search button is click it would generate an error...


please help..thanks...

Recommended Answers

Try addslashes method.

Jump to Post

You can try

$clean_string = str_replace("'","",$search_string);

parameter 1, is what you are searching for, param 2 is what to replace it with, (in this case replace a single ' with nothing) and param 3 is the string you are searching through.

Jump to Post

All 5 Replies

You can try

$clean_string = str_replace("'","",$search_string);

parameter 1, is what you are searching for, param 2 is what to replace it with, (in this case replace a single ' with nothing) and param 3 is the string you are searching through.

try this

$string = addslashes($seachKeyWord);

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.