Zeradin Posted July 22, 2008 Share Posted July 22, 2008 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? Link to comment https://forums.phpfreaks.com/topic/116095-solved-read-file-until-certain-character/ Share on other sites More sharing options...
jonsjava Posted July 22, 2008 Share Posted July 22, 2008 I'd add something like [END] in my script. Then, I'd do something like this <?php $data = <loaded_file>; //the files data loaded into a variable $data_array = explode("[END]", $data); foreach ($data_array as $value){ //manipulate data here } ?> Link to comment https://forums.phpfreaks.com/topic/116095-solved-read-file-until-certain-character/#findComment-596978 Share on other sites More sharing options...
Zeradin Posted July 22, 2008 Author Share Posted July 22, 2008 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. Link to comment https://forums.phpfreaks.com/topic/116095-solved-read-file-until-certain-character/#findComment-596985 Share on other sites More sharing options...
Zeradin Posted July 23, 2008 Author Share Posted July 23, 2008 Well that worked. Awesome! Thanks. I still am having trouble on how to fix the \ problem. The form that people fill out goes to a php file that writes it with the \'s in it How do I get rid of in the script? Link to comment https://forums.phpfreaks.com/topic/116095-solved-read-file-until-certain-character/#findComment-597051 Share on other sites More sharing options...
jonsjava Posted July 23, 2008 Share Posted July 23, 2008 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; } ?> Link to comment https://forums.phpfreaks.com/topic/116095-solved-read-file-until-certain-character/#findComment-597059 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.