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 Quote 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. Quote 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>"; ?> Quote 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. Quote Link to comment https://forums.phpfreaks.com/topic/53540-splitting-strings/#findComment-264942 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.