adding a new line character in a string.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • prasadedathil
    New Member
    • Feb 2007
    • 2

    #1

    adding a new line character in a string.

    Hi friends

    I need to write s string into a log file a string each time I run my php script.

    How could I write the details into a new line each time I run.

    I tried using \n but it is not working.....
    eg:
    $logdetail= "date: ".$todate.$coun t."values inserted\n";
    fwrite($fptr, $logdetail);

    THIS IS VERY URGENT Friends
  • Motoma
    Recognized Expert Specialist
    • Jan 2007
    • 3236

    #2
    Originally posted by prasadedathil
    Hi friends

    I need to write s string into a log file a string each time I run my php script.

    How could I write the details into a new line each time I run.

    I tried using \n but it is not working.....
    eg:
    $logdetail= "date: ".$todate.$coun t."values inserted\n";
    fwrite($fptr, $logdetail);

    THIS IS VERY URGENT Friends
    Welcome to The Scripts!
    Did you use fopen()?

    Comment

    • Atli
      Recognized Expert Expert
      • Nov 2006
      • 5062

      #3
      Hi.

      If your using windows you should do "\r\n" instead of "\n".

      [PHP]$fh = fopen($filename , "a");
      fwrite("I am a new line :D \r\n");
      fclose($fh);[/PHP]

      Comment

      • prasadedathil
        New Member
        • Feb 2007
        • 2

        #4
        for adding a new line caharacter in a string, concatenate the string with a \n enclosed in double quotes.
        eg: $string="new employee"."\n";
        fwrite($fptr, $string);
        This will write the contents of the string '$string' in to the file and take the cursor to the next line of the file.
        So, when you execute the foll: code,
        $emp_name="John ";
        fwrite($fptr, $emp_name);
        The name John will be printed in the next line of the file.

        i.e. new employee
        John

        Comment

        Working...