Andrew R Posted February 11, 2009 Share Posted February 11, 2009 I was wondering why the following script does not work. Basically I want to output each name in a separate text box, separates by a comma. <? $users = array("".$user['user_name'].""); $users = str_replace(" ", "", $users); foreach($users as $key => $value) { ?> <input type="text" value="<? echo $value; ?>" /> <? } ?> The format of user_name is, Andrew,Bob,James,Jim. Link to comment https://forums.phpfreaks.com/topic/144767-solved-str_replace-and-array/ Share on other sites More sharing options...
rhodesa Posted February 11, 2009 Share Posted February 11, 2009 you need to explode() the list: <?php $sep = ","; $users = explode($sep, $user['user_name']); foreach($users as $value) { ?> <input type="text" value="<? echo $value; ?>" /> <?php } ?> Link to comment https://forums.phpfreaks.com/topic/144767-solved-str_replace-and-array/#findComment-759640 Share on other sites More sharing options...
redarrow Posted February 11, 2009 Share Posted February 11, 2009 example <?php $sep = "john,bob,redarrow"; $users = explode(',',$sep); foreach($users as $value) { ?> <input type="text" value="<? echo $value; ?>" /> <?php } ?> your way <?php $sep['users'] = "john,bob,redarrow"; $users = explode(',',$sep['users']); foreach($users as $value) { ?> <input type="text" value="<? echo $value; ?>" /> <?php } ?> Link to comment https://forums.phpfreaks.com/topic/144767-solved-str_replace-and-array/#findComment-759643 Share on other sites More sharing options...
Andrew R Posted February 11, 2009 Author Share Posted February 11, 2009 Thats great. Thanks a million Link to comment https://forums.phpfreaks.com/topic/144767-solved-str_replace-and-array/#findComment-759669 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.