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 https://forums.phpfreaks.com/topic/8239-removing-unsafe-characters-from-a-string/ 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 https://forums.phpfreaks.com/topic/8239-removing-unsafe-characters-from-a-string/#findComment-30024 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 https://forums.phpfreaks.com/topic/8239-removing-unsafe-characters-from-a-string/#findComment-30038 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.