A simple PHP function to clean up user input.
It does following:
- converts & to &
- converts < to <
- converts > to >
- converts “ to "
- and converts line-breaks to <br />
[ad name=”Adsense – text only”]
The Function:
function clean($str) {
$str = preg_replace('/&(?!#[0-9]+;)/s', '&', $str);
$str = str_replace(array('< ', '>', '"'), array('<', '>', '"'), $str);
$str = nl2br($str);
return $str;
}
$str = preg_replace('/&(?!#[0-9]+;)/s', '&', $str);
$str = str_replace(array('< ', '>', '"'), array('<', '>', '"'), $str);
$str = nl2br($str);
return $str;
}
One reply on “Clean Up User-Input & Convert Line-Breaks To BR-tags”
i love it