Jump to content

[SOLVED] Read file until certain character?


Zeradin

Recommended Posts

I have a form that writes into a text file: title, date, time, message and poster

the problem is that they are all single line items except message, which can be multiline. Everytime someone puts a return it messes up the whole read. Is there a way to read to some special character so I can just write to the text file and end every item with that character, therefore negating the whole problem? Thanks.

 

Also is there a simple solution to the fact that my forms post a \ when they get a ' ? I can see that I can turn off the magic quotes or whatever, but will that mess up my code?

So are you saying I'd send to the text file

fwrite($fh, "$poster. '[END]'.$news. '[END]'.$date. '[END]'.$title. '[END]'.") or die('Could not write to file');

and then $data_array would be an array of each variable after the explode?

 

Sorry I've only been doing php for a week or so.

something like this:

<?php
$data = "this is an example i\'m trying it out"; //the files data loaded into a variable
$data_array = explode("[END]", $data);
foreach ($data_array as $value){
$data1 = str_replace("\\", "", $value);
//manipulate data here
print $data1;
}
?>

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.