Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Mar 2007
    Location
    England
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Edit Text Files & Reboot Linux Services

    Hi,

    I want to create a php script from which i want to call from a html file.

    What i want to happen is 2 things.

    1) Edit a text file and add data to it at the bottom of the file, once that has completed i want to reboot a linux service.

    2) Edit a text file and place a "#" before the first character in lines 205 & 298 in that text file

    I am a newbie to php scripting and i would like to learn. I am only 16 years of age and what to know this for a college project.

    Many Thanks

    BlackFish.

  • #2
    Regular Coder
    Join Date
    Jun 2004
    Posts
    130
    Thanks
    0
    Thanked 0 Times in 0 Posts
    files:
    http://nl2.php.net/manual/nl/ref.filesystem.php
    look into the file functions in the php manual,
    like fopen, file_get_contents, file_put_contents, etc, then come back for more questions

    system commands:
    http://nl2.php.net/manual/nl/function.exec.php
    http://nl2.php.net/manual/nl/function.system.php
    look into exec() and system() in the php manual

  • #3
    New Coder
    Join Date
    Mar 2007
    Location
    England
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks,

    i looked at that those docs and managed to get PHP to write data to a text file

    but when it writes the data it does it like this (Please note that the dashes are irrelavent, they are there to seperate how i want the file to look!)

    --------------------------------------------------------------------------
    dogcatcheesefishorange
    --------------------------------------------------------------------------

    What i want the file to do is to write the data like this
    --------------------------------------------------------------------------
    dog
    cat
    cheese
    fish
    orange
    --------------------------------------------------------------------------

    if anyone coulde give me a howto or something i would be grateful

    Many Thanks,

    BlackFish

  • #4
    New Coder
    Join Date
    Mar 2007
    Location
    England
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    anyone?

  • #5
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    To add a newline in a text fle, use \n
    eg:

    $str = "dog\ncat\ncheese\nfish\norange\n";


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •