1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

New Line in PHP

Discussion in 'PHP' started by naimish, Jul 14, 2009.

  1. naimish

    naimish New Member

    Joined:
    Jun 29, 2009
    Messages:
    1,046
    Likes Received:
    18
    Trophy Points:
    0
    Occupation:
    Software Engineer
    Location:
    On Earth
    Please see the code below first.

    Code:
     
    <?php
    $savedata = $_REQUEST['savefeedback'];
    if ($savefeedback == 1){ 
    $data = $_POST['name'];
    $data .= $_POST['feedback'];
    $file = "feedback.txt"; 
    $fp = fopen($file, "a") or die("Couldn't open $file for writing!");
    fwrite($fp, $data) or die("Couldn't write values to file!"); 
    fclose($fp); 
    echo "Your Form has been Submitted!";
    }
    ?>
     
    
    Output :

    NaimishYour Website is very nice.
    JohnI will visit your website now.

    Now What I want to do is, the output should be like this,

    Naimish
    Your Website is very nice.

    John
    I Will visit your website now.

    How can I apply code for a new line in below code ?

    Code:
     
     
    $data = $_POST['name'];
    $data .= $_POST['feedback'];
     
    
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,292
    Likes Received:
    365
    Trophy Points:
    83
    Use <br /> if you use an HTML output
     
  3. naimish

    naimish New Member

    Joined:
    Jun 29, 2009
    Messages:
    1,046
    Likes Received:
    18
    Trophy Points:
    0
    Occupation:
    Software Engineer
    Location:
    On Earth
    Code:
    <html dir="ltr">
        <head>
            <title></title>
            <?php
    $name = $_POST['name'];
    $email .= $_POST['email'];
    
    $count = $email."/n".$name."/n";
    
    $file = fopen("YOURDATAFILE.txt", "a");
    fputs($file, "$name $email");
    fclose($file);
    ?>
        </head>
        <body>
        </body>
    </html>
    Nothing working :(
     
  4. naimish

    naimish New Member

    Joined:
    Jun 29, 2009
    Messages:
    1,046
    Likes Received:
    18
    Trophy Points:
    0
    Occupation:
    Software Engineer
    Location:
    On Earth
    Code:
    fputs($file, "$name $email");
    What needs to put in between $name and $email to get $email printed on next line ?
     
  5. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,292
    Likes Received:
    365
    Trophy Points:
    83
    <br />
     
  6. naimish

    naimish New Member

    Joined:
    Jun 29, 2009
    Messages:
    1,046
    Likes Received:
    18
    Trophy Points:
    0
    Occupation:
    Software Engineer
    Location:
    On Earth
    Code:
    <br /> 
    Thanks a lot Shabbir, I got it done through it.
     
  7. msn90

    msn90 New Member

    Joined:
    Jul 17, 2009
    Messages:
    28
    Likes Received:
    0
    Trophy Points:
    0
    Thanks for this post. it is very helpful.
     
  8. Seema786

    Seema786 New Member

    Joined:
    Jul 29, 2009
    Messages:
    66
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    IT Professional
    Location:
    Banglore
    stranger that <br /> is working in php too.
     
  9. Saket

    Saket New Member

    Joined:
    Jul 21, 2009
    Messages:
    42
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Don't Know
    yeah we can use <br/> in php. just like html ;)
     
  10. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,646
    Likes Received:
    86
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:

Share This Page