[PHP]Strip non alphanumeric chracters

PHP: Hypertext Preprocessor
http://www.php.net/
http://www.zend.com/

[PHP]Strip non alphanumeric chracters

Postby mihu » Fri Jan 30, 2009 11:24 am

Strip non alphanumeric characters from a string with php
Code: Select all
<?php
$string_to_be_stripped = "Hi, I am a string and I need to be stripped...";
$new_string = ereg_replace("[^A-Za-z0-9]", "", $string_to_be_stripped );
?>

Reference: http://www.emanueleferonato.com/2006/07 ... -with-php/

My version:
Code: Select all
function _clean_input($id) {
    $cleaned_input = $this->input->post($id);
   
    if ($cleaned_input !== FALSE) {
        $cleaned_input = preg_replace("/[^\w\s-,]/", "", $cleaned_input);
    }
      
    return $cleaned_input;
}

Reference: http://us.php.net/manual/en/function.preg-replace.php
User avatar
mihu
 
Posts: 183
Joined: Thu Jan 10, 2008 10:44 am

Return to PHP

Who is online

Users browsing this forum: No registered users and 1 guest

cron