BRADERY Posted November 17, 2010 Share Posted November 17, 2010 <?php $filename = "text.txt"; $filename2 = "text2.txt"; $file = file($filename, FILE_SKIP_EMPTY_LINES); foreach($file as $cwb) { $ids[] = "\$id_to_save[] = ".$cwb.";"; } file_put_contents($filename2,implode($ids,"\n\r")); ?> it takes ids from a file and implodes to a new file its supposed to looked like this $id_to_save[] = id; $id_to_save[] = id; $id_to_save[] = id; $id_to_save[] = id; instead it turns out like this $id_to_save[] = 4234324 ; $id_to_save[] = 2342343 ; $id_to_save[] = 3423432 ; $id_to_save[] = 3243244; I've tried trim() but it hasnt seemed to work., any help is appreciated. Thanks Link to comment https://forums.phpfreaks.com/topic/218927-why-is-this-code-not-writing-to-the-file-correctly/ Share on other sites More sharing options...
mikecampbell Posted November 17, 2010 Share Posted November 17, 2010 Was this how you were using trim? foreach($file as $cwb) { $cwb = trim($cwb, " \n\r\0"); $ids[] = "\$id_to_save[] = ".$cwb.";"; } Link to comment https://forums.phpfreaks.com/topic/218927-why-is-this-code-not-writing-to-the-file-correctly/#findComment-1135385 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.