I have a simple string "one two three four".
I would like to 'trim' this string after the (first) whitespace, thus the above string would give "one".
Any help much appreciated.
Chuck
<? $string = "one two three"; $white_pos = strpos($string," "); if($white_pos !== false){ $string = substr($string,0,$white_pos); } ?>
<? $string = 'one two three'; $array = explode (' ', $string); echo $array[0]; // outputs "one" ?>
$string = 'one two three'; echo substr($string,0,strcspn($string, ' '));
Simply a matter of going through the string functions listed in the manual and seeing what they do. Who knows what else you might find along the way?