gerkintrigg Posted May 30, 2007 Share Posted May 30, 2007 Hi. I am trying to make post code search and need to be able to break strings apart by character. I can do it by spaces and things using the explode() function, but I want to be able to get the first letter of the string only, the first and second only, first second and third etc. I forgot how I did it before and can't find any code to help me. Hope you guys and girls can help Thanks, Neil Link to comment https://forums.phpfreaks.com/topic/53540-splitting-strings/ Share on other sites More sharing options...
jitesh Posted May 30, 2007 Share Posted May 30, 2007 http://php.net/split By split get array of characters and use elements as per need. Link to comment https://forums.phpfreaks.com/topic/53540-splitting-strings/#findComment-264559 Share on other sites More sharing options...
chigley Posted May 30, 2007 Share Posted May 30, 2007 I use this: <?php $string = "hello!"; $array = preg_split('//', $string, -1, PREG_SPLIT_NO_EMPTY); echo "<pre>".print_r($array,true)."</pre>"; ?> Link to comment https://forums.phpfreaks.com/topic/53540-splitting-strings/#findComment-264561 Share on other sites More sharing options...
gerkintrigg Posted May 30, 2007 Author Share Posted May 30, 2007 awesome... Thanks guys. I used Chigley's solution and it seems to work the best. Link to comment https://forums.phpfreaks.com/topic/53540-splitting-strings/#findComment-264942 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.