What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » PHP Array Help

PHP Array Help
Author: Message:
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: PHP Array Help
I didn't know the file function read the entire contents of the file to an array...

PHP code:
<?php
    $one = "monkey";
 
    // the HTML source of a URL.
    $lines = file('./one_list.txt');
 
    // Loop through our array, show HTML source as HTML source; and line numbers too.
    foreach ($lines as $line_num => $line) {
        if ($line == $one) {
            echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br />\n";
        }
    }
?>


Or better yet why are you putting your variables in ""
PHP code:
<?php
$one = "monkey";
$two = "baguette";
 
$one_array = file("one_list.txt");
$two_array = file("two_list.txt");
 
if (in_array("$one",$one_array)){    echo"one present!<br />";
    if(in_array("$two",$two_array)){        echo"two present!";
    }
    else{
    echo"two missing!";
    }
}
else{
    echo"one missing!";
}
?>


PHP code:
<?php
$one = "monkey";
$two = "baguette";
 
$one_array = file("one_list.txt");
$two_array = file("two_list.txt");
 
if (in_array($one, $one_array)){    echo"one present!<br />";
    if(in_array($two, $two_array)){        echo"two present!";
    }
    else{
    echo"two missing!";
    }
}
else{
    echo"one missing!";
}
?>


And if the above works you can simplify it:
PHP code:
<?php
    if ( in_array("monkey", file("one_list.txt") ) ) {  echo"one present!<br />";
    if( in_array("baguette", file("two_list.txt") ) ){ echo"two present!"; }
    else{ echo"two missing!"; }
    } else { echo"one missing!"; }
?>


This post was edited on 02-19-2009 at 09:20 PM by matty.
02-19-2009 09:14 PM
Profile E-Mail PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
PHP Array Help - by stoshrocket on 02-19-2009 at 09:07 PM
RE: PHP Array Help - by matty on 02-19-2009 at 09:14 PM
RE: PHP Array Help - by prashker on 02-19-2009 at 09:16 PM
RE: PHP Array Help - by matty on 02-19-2009 at 09:21 PM
RE: PHP Array Help - by prashker on 02-19-2009 at 09:42 PM
RE: PHP Array Help - by stoshrocket on 02-19-2009 at 10:51 PM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On