Return to Snippet

Revision: 1445
at October 9, 2006 11:11 by sorehead


Updated Code
<?php
/* Convert string to underscore_name

Converts "My House" to "my_house".
Converts " Peter's nice car " to "peters_nice_car".
Converts "_88" to "88" */

function string_to_underscore_name($string)
{
    $string = preg_replace('/[\'"]/', '', $string);
    $string = preg_replace('/[^a-zA-Z0-9]+/', '_', $string);
    $string = trim($string, '_');
    $string = strtolower($string);
    
    return $string;
}
?>

Revision: 1444
at October 9, 2006 11:04 by sorehead


Initial Code
<?php
/* Convert string to underscore_name

Converts "My House" to "my_house".
Converts " Peter's nice car " to "peters_nice_car".
Converts "_88" to "88" */

function string_to_underscore_name($string)
{
    $string = preg_replace('/[\'"]/', '', $string);
    $string = preg_replace('/[^a-zA-Z0-9]+/', '_', $string);
    $string = trim($string, '_');
    $string = strtolower($string);
    
    return $string;
}
?>

Initial URL

                                

Initial Description

                                

Initial Title
Convert string to underscore_name

Initial Tags

                                

Initial Language
PHP