danielandlisa Posted January 5, 2009 Share Posted January 5, 2009 php flatfile blog problem Hi i was lucky to get help earlier so i try again . i a problem with the flatfile script and that is that i cant make any line breaks in the form when i try to send data to the flatfile it displays all linebreaks as br after the server handle it. what i want to do is simply make the server handle the linebreaks as html and not text can that be done? the code is blog.php <? echo "<font face=verdana >"; $opFile = "blogfile.txt"; // Opens Blog File to read or dies $fp = fopen($opFile,"r") or die("Error Reading File"); $data = fread($fp, filesize($opFile)); fclose($fp); // Explodes data at line breaks $line = explode("\n", $data); $i=count($line); for ($n=0 ; $n < $i-1 ; $n++ ) { $blog = explode("|", $line[$n]); if (isset($blog[0])) { echo "name: " .$blog[0]."<br>"; echo " date: " .$blog[1]."<br>"; echo " subject: " .$blog[2]."<br>"; echo " message: " .$blog[3]."<br><br>"; } } ?> post.php the file i use the form to post to <?php $filename = "blogfile.txt"; if (!isset($meddelande)) { $namn = $_POST['name']; //$date = $_POST['date']; $ämne = $_POST['subject']; $message = $_POST['message']; } $postdate = date('d M Y'); $blog = $name."|".$postdate."|".$subject."|".$message."|[end]\n" ; $data = fopen($filename, "a"); fwrite($data, $blog); fclose($data); echo "message sent"; ?> And ofcourse i got the post message and text file but i guess you dont need that. / lisa Quote Link to comment https://forums.phpfreaks.com/topic/139591-phpflatfile-form-linebreak/ Share on other sites More sharing options...
premiso Posted January 5, 2009 Share Posted January 5, 2009 nl2br I believe is what you are looking for... <?php $filename = "blogfile.txt"; if (!isset($meddelande)) { $namn = $_POST['name']; //$date = $_POST['date']; $ämne = $_POST['subject']; $message = $_POST['message']; } $postdate = date('d M Y'); $blog = $name."|".$postdate."|".$subject."|".nl2br($message)."|[end]\n" ; // line modified here. $data = fopen($filename, "a"); fwrite($data, $blog); fclose($data); echo "message sent"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/139591-phpflatfile-form-linebreak/#findComment-730266 Share on other sites More sharing options...
danielandlisa Posted January 5, 2009 Author Share Posted January 5, 2009 Hi, thanks again but this time it didnt work. any other suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/139591-phpflatfile-form-linebreak/#findComment-730294 Share on other sites More sharing options...
premiso Posted January 5, 2009 Share Posted January 5, 2009 Maybe I mis-interpreted it... Hi i was lucky to get help earlier so i try again . i a problem with the flatfile script and that is that i cant make any line breaks in the form when i try to send data to the flatfile it displays all linebreaks as br after the server handle it. what i want to do is simply make the server handle the linebreaks as html and not text can that be done? Do you not want it to display as <br>? Instead you would rather it display as \n and you want the HTML to display it like it would display in notepad or another text-editing application? Can you provide an example of a post and how it displays then the same post with how it should display? I think that would help clear things up and help to get you the correct answer, cause I think you contradict yourself in your question, which is where my confusion is coming from. Quote Link to comment https://forums.phpfreaks.com/topic/139591-phpflatfile-form-linebreak/#findComment-730297 Share on other sites More sharing options...
danielandlisa Posted January 5, 2009 Author Share Posted January 5, 2009 I think you got it right the first time want it to display as in a usual xhtml page when i hit a br in the form i want the line to break like text text text text text new line tezt text text as it is now i get a long line without breaks but it displays the br html code right on the page liket his text br Quote Link to comment https://forums.phpfreaks.com/topic/139591-phpflatfile-form-linebreak/#findComment-730300 Share on other sites More sharing options...
premiso Posted January 5, 2009 Share Posted January 5, 2009 Scratch that update post.php and go back to your old one. Then use this to display the data. <?php echo "<font face=verdana >"; $opFile = "blogfile.txt"; // Opens Blog File to read or dies $fp = fopen($opFile,"r") or die("Error Reading File"); $data = fread($fp, filesize($opFile)); fclose($fp); // Explodes data at line breaks $line = explode("\n", $data); $i=count($line); for ($n=0 ; $n < $i-1 ; $n++ ) { $blog = explode("|", $line[$n]); if (isset($blog[0])) { echo "name: " .$blog[0]."<br>"; echo " date: " .$blog[1]."<br>"; echo " subject: " .$blog[2]."<br>"; echo " message: " .nl2br($blog[3])."<br><br>";// changed this line here } } ?> That should display it correctly with the brs in place. Quote Link to comment https://forums.phpfreaks.com/topic/139591-phpflatfile-form-linebreak/#findComment-730303 Share on other sites More sharing options...
danielandlisa Posted January 5, 2009 Author Share Posted January 5, 2009 thanks again, unfortunately it dont work for some reason im sure the code is right but it dont the work done. Maybe its because im running php locally ? Quote Link to comment https://forums.phpfreaks.com/topic/139591-phpflatfile-form-linebreak/#findComment-730310 Share on other sites More sharing options...
premiso Posted January 5, 2009 Share Posted January 5, 2009 thanks again, unfortunately it dont work for some reason im sure the code is right but it dont the work done. Maybe its because im running php locally ? Shouldn't be that problem. Can you post the first few lines of your blogfile.txt inside the [ code] and [ /code] tags (without initial space) It could be that the \n's are throwing off the code and if I have it to test I can provide a more accurate response to the question. Quote Link to comment https://forums.phpfreaks.com/topic/139591-phpflatfile-form-linebreak/#findComment-730313 Share on other sites More sharing options...
danielandlisa Posted January 5, 2009 Author Share Posted January 5, 2009 thanks i appreciate it, the text file looks like this lisa|05 Jan 2009|hello|text tezt text text br text text text|[end] Quote Link to comment https://forums.phpfreaks.com/topic/139591-phpflatfile-form-linebreak/#findComment-730324 Share on other sites More sharing options...
premiso Posted January 5, 2009 Share Posted January 5, 2009 thanks i appreciate it, the text file looks like this lisa|05 Jan 2009|hello|text tezt text text[br] text text text|[end] Is the br in there as [br] ? If so, this would work: <?php echo "<font face=verdana >"; $opFile = "blogfile.txt"; // Opens Blog File to read or dies $fp = fopen($opFile,"r") or die("Error Reading File"); $data = fread($fp, filesize($opFile)); fclose($fp); // Explodes data at line breaks $line = explode("\n", $data); $i=count($line); for ($n=0 ; $n < $i-1 ; $n++ ) { $blog = explode("|", $line[$n]); if (isset($blog[0])) { echo "name: " .$blog[0]."<br>"; echo " date: " .$blog[1]."<br>"; echo " subject: " .$blog[2]."<br>"; echo " message: " .str_replace("[br]", "<br />", $blog[3])."<br><br>";// changed this line here } } ?> I just wonder where/how it gets converted to a [ br]..as I do not see that in your code... Quote Link to comment https://forums.phpfreaks.com/topic/139591-phpflatfile-form-linebreak/#findComment-730329 Share on other sites More sharing options...
danielandlisa Posted January 5, 2009 Author Share Posted January 5, 2009 YES , you are the master . Thanks that did the job. will you be here tomorrow i got some more problems with a login script and sessions? Or am i hopingfor to much? maybe i could even add you to msn ? if you can find the time to help me with some more things i be happy to pay for your time Quote Link to comment https://forums.phpfreaks.com/topic/139591-phpflatfile-form-linebreak/#findComment-730340 Share on other sites More sharing options...
premiso Posted January 5, 2009 Share Posted January 5, 2009 YES , you are the master . Thanks that did the job. will you be here tomorrow i got some more problems with a login script and sessions? Or am i hopingfor to much? Unless I call in sick, I should be. Quote Link to comment https://forums.phpfreaks.com/topic/139591-phpflatfile-form-linebreak/#findComment-730342 Share on other sites More sharing options...
danielandlisa Posted January 5, 2009 Author Share Posted January 5, 2009 OK thanks i really appreciate it , i look forward to it. Quote Link to comment https://forums.phpfreaks.com/topic/139591-phpflatfile-form-linebreak/#findComment-730351 Share on other sites More sharing options...
Maq Posted January 6, 2009 Share Posted January 6, 2009 YES , you are the master . Thanks that did the job. will you be here tomorrow i got some more problems with a login script and sessions? Or am i hopingfor to much? Unless I call in sick, I should be. Hehe, posting on the forums instead of doing your work...? tisk tisk. Quote Link to comment https://forums.phpfreaks.com/topic/139591-phpflatfile-form-linebreak/#findComment-730578 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.