jj20051 Posted October 4, 2011 Share Posted October 4, 2011 I was wondering how you would go about separating words with commas between them into an array. In this case I want users to be able to message multiple other users by entering their names in the following format: user1, user2, user3, user4 and then have php separate those into an array so I can then run them through a foreach(); so they can be sent to the correct users... Any help or functions I should look into would be great... code not necessary, just point me in the right direction thanks! Link to comment https://forums.phpfreaks.com/topic/248370-seperating-commas-into-an-array/ Share on other sites More sharing options...
wigpip Posted October 4, 2011 Share Posted October 4, 2011 use the php explode() function Link to comment https://forums.phpfreaks.com/topic/248370-seperating-commas-into-an-array/#findComment-1275445 Share on other sites More sharing options...
codefossa Posted October 4, 2011 Share Posted October 4, 2011 // String of Users $string = 'user1, user2, user3'; // Split String $users = explode(', ', $string); // Display Array of Users echo '<pre>', print_r($users), '</pre>'; Link to comment https://forums.phpfreaks.com/topic/248370-seperating-commas-into-an-array/#findComment-1275446 Share on other sites More sharing options...
Buddski Posted October 4, 2011 Share Posted October 4, 2011 Or incase you do not include a space with each entry $string= 'user1, user2, user3, user4'; $users = array_map('trim',explode(',',$string)); Link to comment https://forums.phpfreaks.com/topic/248370-seperating-commas-into-an-array/#findComment-1275461 Share on other sites More sharing options...
Deoctor Posted October 4, 2011 Share Posted October 4, 2011 use the explode function of the php. Link to comment https://forums.phpfreaks.com/topic/248370-seperating-commas-into-an-array/#findComment-1275490 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.