pea_1 Posted April 24, 2007 Share Posted April 24, 2007 Hello, i'm trying to figure out how to put the characters of a string into an array, but i can't. Any ideas? Peter Link to comment https://forums.phpfreaks.com/topic/48425-putting-characters-of-a-string-into-an-array/ Share on other sites More sharing options...
ToonMariner Posted April 24, 2007 Share Posted April 24, 2007 They already are (kindof)! $string = 'qwertyuiop'; echo $string{3}; // outputs e depends on what you need but if you truely need a proper bonefide array.. $string = trim('qwertyuiop'); $length = strlen($string); for($i=0; $i < $length; $i++) { if ($string{$i} != ' ') { arr[] = $string{$i}; } } Note: the if statement will make sure you only have characters in the array that are NOT spaces. Link to comment https://forums.phpfreaks.com/topic/48425-putting-characters-of-a-string-into-an-array/#findComment-236780 Share on other sites More sharing options...
pea_1 Posted April 24, 2007 Author Share Posted April 24, 2007 Wow, never knew that. Thanks Link to comment https://forums.phpfreaks.com/topic/48425-putting-characters-of-a-string-into-an-array/#findComment-236782 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.