map200uk Posted May 13, 2007 Share Posted May 13, 2007 hi, just found a problem with part of my project if a ' is present then it screws up the sql query- so, i need toget rid of it, would the best way be to, use regex, and see if string a contains a ' || string b etc and if so, use str_replace("'","",$string); thanks mark Quote Link to comment https://forums.phpfreaks.com/topic/51227-replace-part-of-string/ Share on other sites More sharing options...
chigley Posted May 13, 2007 Share Posted May 13, 2007 Why not just use addslashes() and stripslashes() If you really want to remove them: <?php $string = "O'neil"; $string = str_replace("'", "", $string); echo $string; // Oneil ?> Quote Link to comment https://forums.phpfreaks.com/topic/51227-replace-part-of-string/#findComment-252312 Share on other sites More sharing options...
map200uk Posted May 13, 2007 Author Share Posted May 13, 2007 if i did add slashes this would remove the issue with the mysql query? possibly a better way to handle it than check every string and remove '? thanks Quote Link to comment https://forums.phpfreaks.com/topic/51227-replace-part-of-string/#findComment-252315 Share on other sites More sharing options...
chigley Posted May 13, 2007 Share Posted May 13, 2007 If you add slashes before inserting into the database, this will solve all the problems. You probably don't even need to strip them again later on! Quote Link to comment https://forums.phpfreaks.com/topic/51227-replace-part-of-string/#findComment-252317 Share on other sites More sharing options...
map200uk Posted May 13, 2007 Author Share Posted May 13, 2007 yep solved thanks bud, now to solve the next problem lol Quote Link to comment https://forums.phpfreaks.com/topic/51227-replace-part-of-string/#findComment-252319 Share on other sites More sharing options...
boo_lolly Posted May 13, 2007 Share Posted May 13, 2007 have you tried mysql_real_escape_string()? Quote Link to comment https://forums.phpfreaks.com/topic/51227-replace-part-of-string/#findComment-252359 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.