Page 1 of 1

Php problem

Posted: Thu Apr 22, 2004 4:57 pm
by Kon-Tiki

Code: Select all

$guestbook = file("guestbook.txt");
$guestbook = explode('<hr>', $guestbook);
echo $guestbook[1];
That's the code that's being a donkey. What it should do, is open guestbook.txt as an array, cut it into pieces that end with <hr> and store it as parts of the array (like $guestbook[1], $guestbook[2], etc), then show the first part on the screen.

What it does, is show nothing. It doesn't give an error, but it doesn't show anything either. I tried changing 'hr' into things like "Zeven" and 'Zeven' and made sure there were two entries that contained that, but to no avail. I also tried a different text-file, where I put some random words in, ending with Zeven so it'd cut it there, but didn't work either. If I change $guestbook[1] to $guestbook[0] it does do something. It shows Array, and that's all.

Re:Php problem

Posted: Thu Apr 22, 2004 5:48 pm
by AGI1122
Try $guestbook[0] ;)

The first key created by an explode is 0 not 1.

Re:Php problem

Posted: Thu Apr 22, 2004 6:03 pm
by Kon-Tiki
I tried that, but it doesn't work. It shows Array :-\ You can see it here. The code is [url=http://raf.patat.org/rommel/test.txt[/url] here. Those lines I'm talking about are at the very bottom, but above

Code: Select all

?>
</body>
</html>

Re:Php problem

Posted: Thu Apr 22, 2004 6:57 pm
by AGI1122
Ah no wonder, the problem is that you used "file" file returns an array not a string. :P

Use this:

Code: Select all

$guestbook = file("guestbook.txt");
$guestbook = implode("\r\n",$guestbook);
$guestbook = explode('<hr>', $guestbook);
echo $guestbook[1];

Re:Php problem

Posted: Thu Apr 22, 2004 8:35 pm
by Kon-Tiki
Woohay! It works now. Step two: automatically groupin every fifteen parts into one string, then showing that string and a next page- and a previous page-button, unless it's the first page, then no previous page-button, or if it's the last page, then no next page-button.

*Goes to rummage around in php.net :) *
[size=0]This php sure is fun[/size]

Re:Php problem

Posted: Tue Apr 27, 2004 5:10 pm
by Kon-Tiki
Ran into another problem that seems unexplicable to me.

Code: Select all

if ($beginning == 1) {
echo "<center><a href=\"?page=", $_GET['page']+1, "><img src='tags/right.gif'></a></center>";
}
else {
echo "<center><a href=\"?page=", $_GET['page']-1, "><img src='tags/left.gif'></a></center>";
}
Works fine, but

Code: Select all

if ($beginning == 1) {
echo "<center><a href=\"?page=", $_GET['page']+1, "><img src='tags/right.gif'></a></center>";
}
else {
echo "<center><a href=\"?page=", $_GET['page']-1, "><img src='tags/left.gif'></a></center>";
echo "<center><a href=\"?page=", $_GET['page']+1, "><img src='tags/right.gif'></a></center>";
}
Links to ?page=1%3E%3Cimg%20src='tags/left.gif'%3E%3C/a%3E%3C/center%3E%3Ccenter%3E%3Ca%20href=

Anybody know what's the matter with it?

Re:Php problem

Posted: Wed Apr 28, 2004 2:52 am
by Neo
How about closing the quotes in the <a href> tags?
You've opened them in and then not closed them. Use

Code: Select all

"\"><img src............

Re:Php problem

Posted: Wed Apr 28, 2004 1:16 pm
by Kon-Tiki
Oops. It works now.