?
Solved

file_put_contents

Posted on 2010-01-11
4
Medium Priority
?
233 Views
Last Modified: 2012-05-08
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
Comment
Question by:rgb192
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 82

Accepted Solution

by:
hielo earned 668 total points
ID: 26285640
try:
file_put_contents('output.txt', explode("\n", $output));
0
 
LVL 11

Assisted Solution

by:VanHackman
VanHackman earned 668 total points
ID: 26285731

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
 
LVL 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 664 total points
ID: 26295708
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
 

Author Closing Comment

by:rgb192
ID: 31675635
thanks
0

Featured Post

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question