PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Dale
Forum Contributor
Posts: 466 Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks
Post
by Dale » Sun Feb 20, 2005 8:37 pm
Im using this:
Code: Select all
*snip*
$statsї'url'] = "$mybb_forumurl";
$lines = @file("".$statsї'url']."hum.php");
if(!$lines) {
if(!$statsї'posts'] || !$statsї'threads'] || !$statsї'members']) {
echo "<td colspan="3" bgcolor="#FFFFFF" nowrap><font face="Tahoma" size="1" color="#FF0000"><b>Cannot Find Stats For:<br>$statsїurl]<br><a href="".$statsї'url']."stats.php" target="_blank">View External Stats.</a></b></font></td>";
} else {
echo "<td width="4%" bgcolor="#FFFFFF" nowrap><font face="Tahoma" size="1">".$statsї'posts']."</td>";
echo "<td width="4%" bgcolor="#FFFFFF" nowrap><font face="Tahoma" size="1">".$statsї'threads']."</td>";
echo "<td width="4%" bgcolor="#FFFFFF" nowrap><font face="Tahoma" size="1">".$statsї'members']."</td>";
}
} else {
foreach ($lines as $line_num => $line) {
$input = array(htmlspecialchars($line));
$arrї] = array_reverse($input);
}
$html = implode('', $lines);
echo "<td width="4%" bgcolor="#FFFFFF" nowrap><font face="Tahoma" size="1">$arrї4]</font></td>";
echo "<td width="4%" bgcolor="#FFFFFF" nowrap><font face="Tahoma" size="1">$arrї3]</font></td>";
echo "<td width="4%" bgcolor="#FFFFFF" nowrap><font face="Tahoma" size="1">$arrї2]</font></td>";
}
*snip*
But for some reason its not showing the 4th to last, 3rd to last or the 2nd to last line of the document
hum.php . Its just showing a blank space... why?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Feb 20, 2005 9:04 pm
first off, array[4] is the 5th element. Your code is calling reverse on a single element array as htmlspecialchars returns a string, which is placed as the sole element in an array, which is reversed and then added to an array.
Dale
Forum Contributor
Posts: 466 Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks
Post
by Dale » Mon Feb 21, 2005 6:34 am
feyd wrote: first off, array[4] is the 5th element. Your code is calling reverse on a single element array as htmlspecialchars returns a string, which is placed as the sole element in an array, which is reversed and then added to an array.
What?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Feb 21, 2005 8:36 am
feyd's notes:
array[4] is the 5th element in an array htmlspecialchars returns a string. calling reverse on a single element array is.... useless the actual array is never reversed.
Dale
Forum Contributor
Posts: 466 Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks
Post
by Dale » Mon Feb 21, 2005 6:54 pm
*me = n00b*
So then how do i reverse it then? Because everyones global.php file is different lengths so its usless me trying to return line 101 from the script... so i want to go upwards instead of down.
*me = n00b*
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Feb 21, 2005 7:08 pm
untested example
Code: Select all
$data = @file_get_contents($statsї'url'] . 'hum.php');
if(empty($data))
{
// do your empty junk
}
else
{
$lines = array_slice(preg_split("#\r\n|\n\r|\r|\n#", htmlentities($data, ENT_QUOTES)), -4, 0, true);
var_export($lines);
}
Dale
Forum Contributor
Posts: 466 Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks
Post
by Dale » Mon Feb 21, 2005 7:20 pm
are
^ What are they supposed to be?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Feb 21, 2005 7:25 pm
I don't understand what you are asking.
Dale
Forum Contributor
Posts: 466 Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks
Post
by Dale » Mon Feb 21, 2005 7:28 pm
feyd wrote: I don't understand what you are asking.
In that sample code you posted the word 'are' is in blue... is that what it supposed to be? Or is this supposed to be something else?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Feb 21, 2005 7:31 pm
read the suggestion board for why they appear.. thank your fellow members for it.
if you look at the actual post, they aren't there... as you'll find out if you just quote my post or read the explaination of where the r comes from.