//*function:CLEAN STRING*******************************************************
function clean_string($text) {
$text =
ereg_replace("[,]"," ",$text); //replace , with space
$text = strtolower($text); //lower case
$text = eregi_replace("[^a-z0-9 ']", "", $text); //keep a-z0-9 space '
$text = preg_replace('/[\s\s+]/', ' ', $text); //multiple spaces -> 1
$text = trim($text); //trim
$text_arr = explode(' ',$text); //make into an array
return $text_arr;
}
Saturday, April 5, 2008
CORRECTION php: Cleaning user input text
After reviewing my last post, I came to the conclusion that code should not be bunched together as I did. Sure, it may make the code look sharp and concise, but clarity and user understandability is our second priority (efficiency is our first). So, here is my revision of the code in my last post. I have made it a function, so you can simply call it each time you need to clean a string. Put it in a common_functions.php (or whatever you want to name it) file in directory named "include".
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment