Jump to content

[SOLVED] A Line Break Thread


Zeradin

Recommended Posts

I just have a hard time visualizing where this will go. I have an html form:

<form method="POST" action="newstory.php">
                                        <b>Message</b><br />
				<textarea rows="30" name="message" cols="80"></textarea>
				<br />
				<br />
				<input type="submit" value="Submit" name="newssubmit">
</form>

 

and then in newstory.php I have

 

<?php
if(isset($_POST['newssubmit'])) {
$news = $_POST['message'];
}
$file = "generalnews.txt";
$fh = fopen($file, 'a') or die('Could not open file!');
fwrite($fh, "$news\n") or die('Could not write to file');
fclose($fh);

so it writes into the file with breaks

 

then i read it out in another php file

 

// set file to read
$file = 'generalnews.txt' or die('Could not read file!');
$fh = fopen($file, 'r');
// read file into array
$data_array = fread($fh, filesize($file)) or die('Could not read file!');
fclose($fh);

 

I don't think I'm missing any pertinent parts of that.

Anyway... where do I convert the line breaks to html line breaks? and how do I do it? I'd imagine it needs to be written to the text file with them, but then again maybe the php can see the breaks in the text file and convert it that way. You guys always come through so thanks in advance.

Link to comment
Share on other sites

How can I preserve the data I'm reading it in like

$file = 'generalnews.txt' or die('Could not read file!');
$fh = fopen($file, 'r');
// read file into array
$data_array = fread($fh, filesize($file)) or die('Could not read file!');
fclose($fh);
$data = explode("'[END]'", $data_array);

 

so the last part of it could be multiple lines and the only way I knew how to read that was to break it up using the '[END]' as someone recommended here. I'm pretty sure that just reads it all as a string. Is there any other way to do that?

Link to comment
Share on other sites

Yeah I have a delimiter '[END]' that breaks it up into parts, but when it reads in for example:

 

title'[END]'
date'[END]'
message
with line
breaks'[END]'

 

with

// set file to read
$file = 'generalnews.txt' or die('Could not read file!');
$fh = fopen($file, 'r');
// read file into array
$data_array = fread($fh, filesize($file)) or die('Could not read file!');
fclose($fh);
// count the number of lines and divide it into number of news stories
$lines = count($data);
$data = explode("'[END]'", $data_array);
?>

 

it lists the message with line breaks as just a big string, no? so I figure I have to put the html line breaks into the text file so it reads it out of there. Or is there another way to read out the data into the array not as a string?

Link to comment
Share on other sites

oh F#@$

sorry i just didn't understand how the function worked. I was using it outside of the echo trying to convert the variable to a new one and then echo it, once i put it after the echo it worked perfectly. Thanks so much... sorry for being such a pain.

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.