PHP

trim — Strip whitespace (or other characters) from the beginning and end of a string
string trim ( string $str [, string $charlist ] )

Example #1 Trimming array values with trim()

<?php
function trim_value(&$value


    
$value trim($value
); 
}

$fruit = array('apple','banana '' cranberry '
);
var_dump($fruit
);

array_walk($fruit'trim_value'
);
var_dump($fruit
);

?>

Example #2

<?php
$string
= 'This string  has   no    whitespaces.'
;
echo
ereg_replace( ' +', '', $string
);
?>
Output: Thisstringhasnowhitespaces.

  • Comment 2010-01-19 14:16
if(!$auth[admin]) {
    $rg_name = ereg_replace( ' +', '', $rg_name );
    $rg_name=substr($rg_name,0,4)."○";
}