php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45138 What is this?
Submitted: 2008-05-30 13:47 UTC Modified: 2008-05-30 14:28 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: bahadir at eggdrop dot gen dot tr Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 5.2.6 OS: Windows XP
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: bahadir at eggdrop dot gen dot tr
New email:
PHP Version: OS:

 

 [2008-05-30 13:47 UTC] bahadir at eggdrop dot gen dot tr
Description:
------------
in_array or file function doesn't work.

Reproduce code:
---------------
My test.php File:
<?php

$findme = 'bahadir';
$inthere = file('names.txt');

if (in_array($findme, $inthere)) {
	echo 'yes! :)';
} else {
	echo 'no :(';
}

?>

My names.txt File:
bahadir
baris
alper
halil

Expected result:
----------------
Result:
no :(

Why?


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-05-30 13:55 UTC] felipe@php.net
See the output: var_dump($inthere); 

The ignore the newlines use the second parameter (flags) with FILE_IGNORE_NEW_LINES.
 [2008-05-30 14:23 UTC] bahadir at eggdrop dot gen dot tr
var_dump($inthere);

Result:

array(4) { [0]=> string(8) "bahadir " [1]=> string(6) "baris " [2]=> string(6) "alper " [3]=> string(5) "halil" }
 [2008-05-30 14:28 UTC] felipe@php.net
Exactly, the last char is \n. "foo\n" != "foo".
Again, use the flag FILE_IGNORE_NEW_LINES.


Thanks.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 00:01:27 2024 UTC