PHP – Make Safe Input

The given PHP example makes a string as a safe string. 

Code Example:
<?php
// Function for cleaning any input, submitted by any form etc.
function clean_input($i){
    if(!get_magic_quotes_gpc()) $i = addslashes($i);
    $i = rtrim($i);
    $look = array('&', '#', '<', '>', '"', '\'', '(', ')');
    $safe = array('&amp;', '&#35', '&lt;', '&gt;', '&quot;', '&#39', '&#40;', '&#41;');
    $i = str_replace($look, $safe, $i);
    return $i;
}

$string = "this & that";
clean_input($string);
?>

Post to Twitter Post to Digg Post to Facebook Post to Google Buzz Send Gmail

Leave a Comment

Your email address will not be published. Required fields are marked *