Beauford.2005 <[EMAIL PROTECTED]> wrote:
> Hi,

Hello

> 
> Sorry for the extra emails, but I thought I had this licked, but now
> other problem pop up. As I said, I have a file with many lines like
> <Option Value="3">Alfredsson in it. I have been able to read the file
> into an array and display it, but I am trying to do a comparison IF
> statement and no matter what I try I can't figure out what to compare.
> To explain better here is my code so far.
> 
> $filename = "players.inc";
> 
> $fd = fopen ($filename, "r");
> while (!feof ($fd)) {
>   $buffer = fgets($fd);
>   $list[] = $buffer;
> }
> fclose ($fd);

Have you looked at the file() function? it does all this work for you.
http://php.net/file


> 
> for($i = 0; $i < 131; $i++) {
>       if($list[$i] != ?????????  {
>               echo "<BR>".htmlspecialchars($list[$i]); }
> }     
> 
> So using the example above what would I use where the question marks are
> if I wanted to display everything but this line - <Option
> Value="3">Alfredsson. I have tried a variety of ways to do this:

Be careful with loops like this you might want to use the foreach
statement in this case

http://us3.php.net/foreach

> 
> i.e
> 
> $p = "<Option Value=\"131\">Alfredsson";
> 
> for($i = 0; $i < 131; $i++) {
>       if(htmlspecialchars($list[$i]) != $p)  {
>               echo "<BR>".htmlspecialchars($list[$i]); 
>       }
> }     

first of you dont want to compare the value with the htmlspecialchar()
function, only use that to translate html chars like < to &lt; so the
browser is will display the html code instead of rendering it.

second, the fgets() you used above still has the carriage return on it
so you will need to chomp that off or add it to your compare string. 

http://php.net/trim

> 
> This is just a sample script that I want to get running before I
> actuaaly put it into use, so any help is appreciated.

I hope that helps you getting it running.

> 
> 
 
Curt
-- 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to