Switch0r Posted April 24, 2006 Share Posted April 24, 2006 does anyone know of a function (inbuilt or otherwise) that can strip all of the unsafe chars from a string? ie. ; : " ' ...etc in one go? or will i have to just keep using the str_replace function over and over? Quote Link to comment Share on other sites More sharing options...
slashemail Posted April 24, 2006 Share Posted April 24, 2006 I would suggest you a combination of functions like[code]htmlspecialcharsstrip_tagsstripslashesmysql_escape_string #For inserting into the database(Mysql)[/code]Hope this helps Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted April 24, 2006 Share Posted April 24, 2006 You can use preg_raplace like so:[code]<?php$string = "This \"string\" has; : got some 'unsafe' chars!";$string2 = preg_replace("([;:\"'])", "", $string);echo $string2;?>[/code]Or you can use str_replace like so:[code]<?php$string = "This \"string\" has; : got some 'unsafe' chars!";$string2 = str_replace(array(";", ":", "\"", "'"), "", $string);echo $string2;?>[/code] Quote Link to comment 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.