Jump to content

why is this code not writing to the file correctly?


BRADERY

Recommended Posts

<?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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.