Page 1 of 1

Why's my reverse_array() not working?

Posted: Sun Feb 20, 2005 8:37 pm
by Dale
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&#1111;url]<br><a href="".$stats&#1111;'url']."stats.php" target="_blank">View External Stats.</a></b></font></td>";
&#125; else &#123;
echo "<td width="4%" bgcolor="#FFFFFF" nowrap><font face="Tahoma" size="1">".$stats&#1111;'posts']."</td>";
echo "<td width="4%" bgcolor="#FFFFFF" nowrap><font face="Tahoma" size="1">".$stats&#1111;'threads']."</td>";
echo "<td width="4%" bgcolor="#FFFFFF" nowrap><font face="Tahoma" size="1">".$stats&#1111;'members']."</td>";
&#125;
&#125; else &#123;
foreach ($lines as $line_num => $line) &#123; 
$input  = array(htmlspecialchars($line));
$arr&#1111;] = array_reverse($input);
&#125;
$html = implode('', $lines);
echo "<td width="4%" bgcolor="#FFFFFF" nowrap><font face="Tahoma" size="1">$arr&#1111;4]</font></td>";
echo "<td width="4%" bgcolor="#FFFFFF" nowrap><font face="Tahoma" size="1">$arr&#1111;3]</font></td>";
echo "<td width="4%" bgcolor="#FFFFFF" nowrap><font face="Tahoma" size="1">$arr&#1111;2]</font></td>";
&#125;
*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?

Posted: Sun Feb 20, 2005 9:04 pm
by feyd
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.

Posted: Mon Feb 21, 2005 6:34 am
by Dale
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.

8O What?

Posted: Mon Feb 21, 2005 8:36 am
by feyd
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.

Posted: Mon Feb 21, 2005 6:54 pm
by Dale
*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*

Posted: Mon Feb 21, 2005 7:08 pm
by feyd
untested example

Code: Select all

$data = @file_get_contents($stats&#1111;'url'] . 'hum.php');
if(empty($data))
&#123;
// do your empty junk
&#125;
else
&#123;
  $lines = array_slice(preg_split("#\r\n|\n\r|\r|\n#", htmlentities($data, ENT_QUOTES)), -4, 0, true);
  var_export($lines);
&#125;

Posted: Mon Feb 21, 2005 7:20 pm
by Dale
are


^ What are they supposed to be?

Posted: Mon Feb 21, 2005 7:25 pm
by feyd
I don't understand what you are asking.

Posted: Mon Feb 21, 2005 7:28 pm
by Dale
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?

Posted: Mon Feb 21, 2005 7:31 pm
by feyd
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.:roll: