Page 2 of 2
while loops
Posted: Mon Sep 26, 2005 3:33 pm
by Scott
[color=\"#000000\"]You\'re probably trying to confuse it a bit much. Try this: [code]<?php
$tnum = "Five";
$file = "Cups.txt";
$found = FALSE;
$desc = find_desc($tnum, $file);
echo $desc;
function find_desc($text, $file)
{
$lines = file($file);
foreach ($lines as $line_num => $line) {
$linenum = (int) $line_num;
$linenum++;
$t = strpos($line, $text);
if ($found === TRUE)
{
echo $line;
}
if($t !== false)
{
$found = TRUE;
}
}
}
?>[/code]
Not tested it, but it *should* work <img src=\'
http://www.killanet.net/forum3/public/s ... unsure.gif\' class=\'bbc_emoticon\' alt=\':unsure:\' /> [/color]
while loops
Posted: Mon Sep 26, 2005 3:51 pm
by Vercz
[color=\"green\"]err...that code returns the entire contents of the file <img src=\'
http://www.killanet.net/forum3/public/s ... >/blum.gif\' class=\'bbc_emoticon\' alt=\':P\' /> lol thanks anyway?[/color]
while loops
Posted: Mon Sep 26, 2005 4:30 pm
by Scott
Ah, yeah. After echo $line; put $found = FALSE; That should stop it returning anything else.
while loops
Posted: Tue Sep 27, 2005 12:30 am
by Vercz
[color=\"green\"]...now it returns nothing :| [/color]
while loops
Posted: Tue Sep 27, 2005 11:51 am
by radar
Why are cups kept in a file? :\
while loops
Posted: Tue Sep 27, 2005 11:58 am
by Vercz
[color=\"green\"]probably for the same reason that suits, swords and shields are...
that reason? nfi tbh <img src=\'
http://www.killanet.net/forum3/public/s ... >/blum.gif\' class=\'bbc_emoticon\' alt=\':P\' />[/color]
while loops
Posted: Tue Sep 27, 2005 2:32 pm
by Scott
[code]<?php
$tnum = "Five";
$file = "Cups.txt";
$desc = find_desc($tnum, $file);
echo $desc;
function find_desc($text, $file)
{
$found = FALSE;
$lines = file($file);
foreach ($lines as $line_num => $line) {
$linenum = (int) $line_num;
$linenum++;
$t = strpos($line, $text);
if ($found === TRUE)
{
echo $line;
return;
}
if($t !== false)
{
$found = TRUE;
}
}
}
?>[/code]
All workie. At least, thats what I think you\'re trying to do.
while loops
Posted: Wed Sep 28, 2005 1:38 am
by Vercz
[color=\"green\"]...it still doesnt show anything <img src=\'
http://www.killanet.net/forum3/public/s ... #>/cry.gif\' class=\'bbc_emoticon\' alt=\':(\' /> [/color]
while loops
Posted: Wed Sep 28, 2005 3:02 am
by radar
Can I have a copy of the file please?
while loops
Posted: Wed Sep 28, 2005 3:04 am
by Vercz
[color=\"green\"]Cups.txt? sure... [url=\"http://vercz.killanet.net/tst/Cups.txt\"]http://vercz.killanet.net/tst/Cups.txt[/url] =) [/color]
while loops
Posted: Wed Sep 28, 2005 7:19 am
by Scott
Ah...that makes sense. It is working, working too well. The script will print the line directly following the word \"Five\". Since your following line is a blank line...you see a blank line. Remove the empty lines and it\'ll work <img src=\'
http://www.killanet.net/forum3/public/s ... /smile.gif\' class=\'bbc_emoticon\' alt=\':)\' />
while loops
Posted: Wed Sep 28, 2005 7:51 am
by Vercz
[color=\"green\"]...im not stupid <img src=\'
http://www.killanet.net/forum3/public/s ... el_not.gif\' class=\'bbc_emoticon\' alt=\'(not)\' />
thanks scott <img src=\'
http://www.killanet.net/forum3/public/s ... iggrin.gif\' class=\'bbc_emoticon\' alt=\':D\' /> and you too radar <img src=\'
http://www.killanet.net/forum3/public/s ... iggrin.gif\' class=\'bbc_emoticon\' alt=\':D\' /> <img src=\'
http://www.killanet.net/forum3/public/s ... >/good.gif\' class=\'bbc_emoticon\' alt=\'(Y)\' /> <img src=\'
http://www.killanet.net/forum3/public/s ... >/good.gif\' class=\'bbc_emoticon\' alt=\'(Y)\' /> [/color]