Home >Backend Development >PHP Tutorial >Solution to the problem that there are spaces in the array when php file is read

Solution to the problem that there are spaces in the array when php file is read

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-25 08:56:111384browse
  1. /**
  2. * Read configuration file
  3. * edit: WWW.JBXUE.COM
  4. */
  5. $encodename='Existing characters';
  6. $lines = @file('ske.txt');
  7. var_export($lines);
  8. if(in_array($encodename,$lines))
  9. //The judgment here fails because: the array read by file contains a number change symbol.
Copy code

Solution:

  1. $lines =array_map('rtrim',file('ske.txt'));
  2. var_export($lines);
  3. if(in_array($encodename,$lines))
  4. //--The judgment here is successful
Copy the code

Attached is the usage of the array_map() function: arrayarray_map( callback callback, array arr1 [, array ...] ) array_map() returns an array that contains all the cells in arr1 after the callback has been applied. The number of arguments accepted by the callback should be consistent with the number of arrays passed to the array_map() function.



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn