php echo to a txt file

Posted on 2011-10-07
Last Modified: 2012-05-12
I create my ouput string and then:

 echo $output;

It goes to the display

How can I send it to a text file instead?
Question by:robrodp
    LVL 13

    Accepted Solution

    do you want to add to a file or write to a new file?
    If you want to add to a file then you can do this
    $reused = file_get_contents($pathToFile);<-- this gives you a string of current file contents
    $add = "New content"
    $updated = $reused . $add;
    file_put_contents($pathToFIle, $updated);<-- writes out updated file

    Open in new window

    LVL 13

    Expert Comment

    If you want just a new file that you can skip the first part and just do the file_put_contents to write out a brand new file.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    Suggested Solutions

    This is a general how to create your own custom plugin system for your PHP application that you designed (or wish to extend a third party program to have plugin functionality that doesn't have it yet).  This is not how to make plugins for existing s…
    Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
    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.

    734 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

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now