Jump to content

[SOLVED] php flatfile problem


Loran

Recommended Posts

Basically, I have a 'system' in place that is meant to 'book' a calendar date. The user selects a date, and a message. The message is stored in a text file, with each row holding a specific dates information, with the info separated by double pipes "||", I'm using file() to read each row into an array, then for each array value, I am explode() ing the row so I can use each different variable.

Read the link below if you don't understand what I mean. (Or just interested...)

http://www.spoono.com/php/tutorials/tutorial.php?id=32

eg.

 

$CalDate||$author||$message

 

The problem is if the user hits 'enter' inside the message 'textbox', It 'destroys' the message. Because now the message is not included with file() because file() is reading the row, and the rest of the message is on the row below. So later, if you try to view the reason that the date was booked you get half the message.

The text file looks like this (with an enter in the text):

 

$CalDate||$author||Lorem ipsum dolor (enter)
sit amet

And the display is:

$date booked by $author

message:

Lorum ipsum dolor

 

At the moment this is what the message variable looks like with the function(s) I'm trying at the moment.

 

$message = trim(nl2br(htmlentities($_POST['message'], ENT_QUOTES, 'UTF-8')));

 

Basically what I want to do is

  • protect against things like a user injecting javascript (htmlentities),
  • keep the look of the user's message the same, but still being held on one line in a text file (nl2br)
  • And to get rid of the newline characters that are causing the problem (I thought trim() would do this).

 

I've tried several different methods because nothing has worked and I have searched php.net for a function that might do what I want, but to no avail

 

If anyone knows of a function that replaces 'enters' or newlines with br 's, but keeps it in one line, please let me know!

 

Sorry if the above is really long but I thought I'd try to explain as best I can.

Thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/150532-solved-php-flatfile-problem/
Share on other sites

Can you just replace the returns with something say a <br> tag and then convert it back.

 

<?php

$content = $_POST['message'];
$c_return = chr(13);
$content = str_replace($c_return,"<br>",$content);

?>

Not sure if this is any help or not since I'm new but I hope it does 

Stephen


Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.