How Come This Does Not Work?

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

Post Reply
icesolid
Forum Regular
Posts: 502
Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY

How Come This Does Not Work?

Post by icesolid »

Code: Select all

<?php
$array = array(@fopen("file.php", "r"));

if(in_array($query, $array, TRUE)) &#123;
    echo "Results were found.";
&#125; else &#123;
    echo "No results were found.";
&#125;
?>
The $query variable is coming from a form I have set up.
samscripts
Forum Commoner
Posts: 57
Joined: Tue Apr 23, 2002 4:34 pm
Location: London, UK

Post by samscripts »

Hi, I'm assuming that you want to read a list of values from file.php into the array and then see if $query is in them?

You need to use:

Code: Select all

$array = file("file.php");
to read the contents of a file into an array (of lines from the file)

Code: Select all

$array=array(@fopen("file.php", "r"));
creates an array containing 1 value, which is the return value of the fopen function. Which is probably not what you want to do.

Sam
Post Reply