| function clear_value($string) { |
| //Trims white space from the front and back of string |
| $string = trim($string); |
| //Strips tags from string |
| $string = strip_tags($string); |
| //Escapes string |
| $string = mysql_real_escape_string($string); |
| //Returns the string |
| return $string; |
| } |
| |
| /* Example of use |
| <? |
| function clear_value($string) { |
| $string = trim($string); |
| $string = strip_tags($string); |
| $string = htmlspecialchars($string); |
| return $string; |
| } |
| |
| $value = $_GET['value']; |
| $value = clear_value($value); |
| echo $value; |
| |
| //Value is now trimmed, stripped of any tags, and special characters are converted into proper HTML |
| */ |
| |
| //Any number of string functions may be added into clear_value(). |
| //With this function, your code becomes a bit cleaner. |