MrXander Posted October 1, 2007 Share Posted October 1, 2007 Hi there, Wondering if someone can point out where I'm being thick... Basically, I am making a news script using flatfile. Below is how the script stores the news post (this isn't the problem, keep reading) $theNews = ""; $theNews .= 'Welcome,General,Test'; $theNews .= 'Test,General,Hmm?'; Then, I am trying to make a list of all news posts so that users can edit a single post if they wish. I want to seperate the news posts, so I thought of using the following code: $string = "'"; $theNewsPosts = explode($string, $theNews); $count = count($theNewsPosts); echo $count; But it only picks up the first line, so can anyone help? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/71433-question-re-explode/ Share on other sites More sharing options...
BlueSkyIS Posted October 1, 2007 Share Posted October 1, 2007 so can anyone help advice: you're going to have one heck of a time doing this without a real database. Quote Link to comment https://forums.phpfreaks.com/topic/71433-question-re-explode/#findComment-359551 Share on other sites More sharing options...
effigy Posted October 1, 2007 Share Posted October 1, 2007 I second the database comment. What is the format of the data exactly? Are there titles to the posts, or just posts? Are single posts always in single quotes? Quote Link to comment https://forums.phpfreaks.com/topic/71433-question-re-explode/#findComment-359556 Share on other sites More sharing options...
MrXander Posted October 1, 2007 Author Share Posted October 1, 2007 I second the database comment. What is the format of the data exactly? Are there titles to the posts, or just posts? Are single posts always in single quotes? I agree with the database comment, but I know a lot of people who don't have a clue about databases, so I thought I'd make something to help. Anyway, the format? ex: $theNews .= 'Welcome,General,Test'; "Welcome" = The title "General" = The category it's posted in "Test" = The body of the post Quote Link to comment https://forums.phpfreaks.com/topic/71433-question-re-explode/#findComment-359559 Share on other sites More sharing options...
BlueSkyIS Posted October 1, 2007 Share Posted October 1, 2007 if each news article will have it's own line in the file, use file() to read the file into an array, one line in each element. http://us.php.net/file Then you could loop over all of them exploding on comma, but watch out for commas in the title, category and body. Quote Link to comment https://forums.phpfreaks.com/topic/71433-question-re-explode/#findComment-359564 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.