note 74161 added to function.in-array
| From: | hirens85 at gmail dot com | Date: | Wed, 28 Mar 2007 04:15:13 +0000 |
| Subject: | note 74161 added to function.in-array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-124866@lists.php.net to get a copy of this message | ||
I am trying to write a script that takes a text file with entries
aa
bb
cc
dd
ee
ff
gg
exactly as typed above, each entry seperated by the enter key, and put them into an array. I want
to be able to search through this array and check if bb exists in the array and if it does I want
the program to print something of my choice. I have been trying this for some time with no luck.
Here is my code that doesn't work.
<?php
$filename = "file.txt";
$contents = file($filename);
if (in_array("bb", $contents)) {
echo "bb 1";
else
echo "bb 0";
}
?>
----
Server IP: 216.194.113.175
Probable Submitter: 67.83.148.180
----
Manual Page -- http://www.php.net/manual/en/function.in-array.php
Edit -- https://master.php.net/note/edit/74161
Del: integrated -- https://master.php.net/note/delete/74161/integrated
Del: useless -- https://master.php.net/note/delete/74161/useless
Del: bad code -- https://master.php.net/note/delete/74161/bad+code
Del: spam -- https://master.php.net/note/delete/74161/spam
Del: non-english -- https://master.php.net/note/delete/74161/non-english
Del: in docs -- https://master.php.net/note/delete/74161/in+docs
Del: other reasons-- https://master.php.net/note/delete/74161
Reject -- https://master.php.net/note/reject/74161
Search -- https://master.php.net/manage/user-notes.php