note 16883 modified in function.array-search by zak
| From: | zak@php.net | Date: | Sat, 17 Nov 2001 14:33:55 +0000 |
| Subject: | note 16883 modified in function.array-search by zak | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-20952@lists.php.net to get a copy of this message | ||
NOTE!!
When using "file()" to load the contents of a file into an array, newlines
("\n") and carriage returns ("\r") are left on each line of the array. These
characters cause functions like array_search() to appear to fail as the line endings are somewhat
hidden.
Use something like this to do a cleanup before using array_search() or in_array():
$array = str_replace (array("\r", "\n"), '', file ($file));
--was--
NOTE!!
When using "file" to load the contents of a file into an array newlines "\n" are
inclued on each line of the array. The newlines cause functions like array_search to appear to fail
as the newline is somewhat hidden.
Use something like this to do a cleanup before using array_search or in_array:
foreach (file ('test.txt') as $line) {
$array[] = substr ($line, 0, -1);
}
http://www.php.net/manual/en/function.array-search.php