Written by: John | 30th Jun 2014
While developing a php based on-line shop I came across a neat little function to remove those pesky unwanted chars from post or get type mysql queries using str_replace() & an array(). But this little function proves quite useful for all kinds of character removal situations. This function is no way revolutionary, unique or new, but never the less it is very useful so I thought I would share it.
The function:
<?php function cl_str($in_str) { // can be any char(s) you like $to_remove= array("#","%",">","<", "/", "[", "]", "?", "-"); $new_str = str_replace($to_remove, "", $in_str); return $new_str; } ?>
The usage:
<?php $some_text = "<blah blah ?-->"; $new_text = cl_str($some_text); echo $new_text; //returns "blah blah" ?>