• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 238
  • Last Modified:

file_put_contents

is this the correct format
file_put_contents('output.txt', implode("\n", $output));

because i get no output and a warning
Warning: implode() [function.implode]: Invalid arguments passed
0
rgb192
Asked:
rgb192
3 Solutions
 
hieloCommented:
try:
file_put_contents('output.txt', explode("\n", $output));
0
 
VanHackmanCommented:

Yes the error is in the implode function.
$output mus be a array.

Here the example:
<?php

$array = array('lastname', 'email', 'phone');
$info  = implode("\n", $array);


file_put_contents('output.txt', $info);

?>

Open in new window

0
 
Ray PaseurCommented:
Your answer depends on what is in $output, and we do not know that from the post.  But here are some possibilities...

If $output contains a string of data with end of line markers (learn about the PHP_EOL constant) then you do not need to do anything more than what is in the code snippet.

If $output contains an array of data elements without end-of-line characters, and you want each of these data elements on a separate line in the output file, you need something like this:

$modified_output = implode(PHP_EOL, $output) . PHP_EOL;
file_put_contents('output.txt', $modified_output);

If $output contains an array of data elements WITH end-of-line characters, and you want each of these data elements on a separate line in the output file, you need something like this:

$modified_output = implode("", $output);
file_put_contents('output.txt', $modified_output);

Best regards, ~Ray

file_put_contents('output.txt', $output);

Open in new window

0
 
rgb192Author Commented:
thanks
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now