Aftermath Posted May 9, 2006 Share Posted May 9, 2006 Hello, I'm new to php and I have been having difficulty :P I have something similar to a shoutbox and in it I have 4 fields; User, Tag, Date, and Title. My problem is when I try to display the string. I can't get it formatted the way I want and I can't find a tutorial out there that describes what I need. [code]<?php$name = $_POST["name"];$tag = $_POST["tag"];$title = $_POST["title"];$newdate = date("H:i");if($name && $tag) {$file = "blog.dat";$filecopy = $title . ".dat";$newtxt = ($name . "," . $newdate . "," . $tag . "," . $title ."\n");.....<?php$boardarray = file("blog.dat");while (list(,$oneline) = each($boardarray)) { $name = substr($oneline,0,strpos($oneline,",")); /*$sdate = substr($online,strpos($oneline,",")+1,strlen($oneline)); $tag = substr($online,strpos($sdate)+1,strlen($oneline));*/ $tag = substr($oneline,strpos($oneline,",")+1,strlen($oneline)); if ($name && $tag) echo "<b>" . $name . "</b>" . $tag . "<br />";}?>.....[/code]Here is what I have been trying to get working. What is happening is it formats the User only and afterwards just posts the rest of the data in the file. I think the problem is in that I don't know how to set up the string commands to start reading at the second comma (since it's a comma delimited file). Any help would be much appreciated. Quote Link to comment Share on other sites More sharing options...
michaellunsford Posted May 9, 2006 Share Posted May 9, 2006 looks like the long way arround. If you aren't oppsoed to arrays, you could just explode the contents:[code]while (list(,$oneline) = each($boardarray)) { $myarray=explode(",",$oneline); list($name,$newdate,$tag,$title) = $myarray; if ($name && $tag) echo "<b>" . $name . "</b>" . $tag . "<br />";}[/code] Quote Link to comment Share on other sites More sharing options...
Aftermath Posted May 9, 2006 Author Share Posted May 9, 2006 Thanks. I will try this and post my results. But this is all new to me so I don't really know what I'm doing exactly.Ok,it worked ^_^ thanks a lot. But I was wondering if I could reverse the order it was displayed in so that the last tag is the first displayed Quote Link to comment Share on other sites More sharing options...
michaellunsford Posted May 9, 2006 Share Posted May 9, 2006 typically, sorting is not practical with text files.you could write it in reverse order. backup your text file, then try the following:$filedata=file_get_contents($file); // will copy the existing file to a varialbe.then open your file using the "w" flag (write, file pointer at beginning), write the content, then write the $filedata variable behind it.check your text file -- the last entry should be first, followed by the remainder of the file.It's not perfect (you still can't sort), but the data is in the order you want. Quote Link to comment Share on other sites More sharing options...
Aftermath Posted May 9, 2006 Author Share Posted May 9, 2006 [code]$stringData = $newtxt;$stringData .= $filedata;[/code]Thanks alot! I got it to work after figuring out what the '.=' does lol. Quote Link to comment 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.