Jump to content

how can i give text HTML formatting after a usser subits a form


Baxt01
Go to solution Solved by Baxt01,

Recommended Posts

i have a form with a <textarea> on it and the usser will submit a list into the text area once they click submit this list is saved into a .txt file on my server the usser's list is formatted as

 

item1

item2

item3

item4

item5

item6

item7

item8

item9

item10

and so on,

when they hit submit and this list is saved in my .txt file the list becomes

 

item1item2item3item4item5item6item7item8item9item10andsoon

 

then once saved i am ussing the php to display this on the ending page like this  <?php include('top100stats.txt'); ?>

to open the contents of the txt file
 

i need some how to keep the orignal list formatting so that each item is on a new line of course there is the list tags <li> but how do i add this tags to my saved .txt file

Link to comment
Share on other sites


<form method="post">
    <textarea name="textarea"></textarea>
    <input type="submit" />
</form>
<?php
$file = "text.txt";
$text = $_POST["textarea"];
$text_ok = nl2br($text);
file_put_contents($file, $text_ok);
include "text.txt";
?>

 

Edited by cataiin
Link to comment
Share on other sites

sorry been offline a little while here just startted back into full time employement haha,

think i am missing my computer already,

thanks for the help but yet again i hit another issue now i am startting to wonder why i want to learn php i have so many issues with my codes,

 

here is my script so far:

 

<?php

 

$player_name = $_POST['player_name'];
$fp = fopen('top100stats.txt', 'w');

fwrite($fp, $player_name);

fclose($fp);
echo '<h2>You data has been saved in a text file!</h2>';

 

?>

 

ok i thought i was getting there when i submitted my form and i recived back the message from the "echo"

However when i go onto my server and open top100stats.txt it is blank there are no saved records

so the server is telling me that a record has been creatted but in fact it is not anyone got any idea why its not saving and not giving an error????????????

Link to comment
Share on other sites

Make sure your error_reporting is set to E_ALL or -1 and display_errors is set to 'On' or 1. You should be receiving some kind of error.

In any case, add some debugging:

$fp = fopen('top100stats.txt', 'r'); //open the file read-only to verify that it exists.
if ( $fp === false ) { //cannot open the file
   echo "Error while attempting to open the file.";
} else { // file opened successfully, display message
   echo '<h2>File exists!</h2>';
}
Edited by DFulg
Link to comment
Share on other sites

  • Solution

ok now i again thank you all for been so kind with promp helping of me;

and have to say i think the reason i am loving learning PHP is that any error i have had so far is usually dumb and i can work it out with little prompts i just have to go away to work and come back and take a frsh look at my coding and suddenly the issue pops right out at me hahaha

i was putting the coding that catain gave me into the wrong file and forgot to change the field names to match my form fields /DOH

thanks again peoples

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.