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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.