1.txt of content:
This is the test file.
The PHP code is as follows:
When the above code executes, there is no way to successfully find the location of the "test" in the 1.txt file.
Reply content:
1.txt of content:
This is the test file.
The PHP code is as follows:
When the above code executes, there is no way to successfully find the location of the "test" in the 1.txt file.
See TXT to know is the coding problem, 测试 is in the PHP file, so is the PHP file encoding (should be UTF-8), TXT file must be made with the default Notepad, is GBK encoded.
- Decomposition test, first put
file_get_contents("1.txt") the content into a variable, see what exactly is.
- Use the
getcwd() function to look at the working directory of your PHP files.
The working directory that executes the PHP script is probably not always in the same directory as you would think, in the PHP script.
The simplest, one-line shell command breaks this erroneous perception:/usr/bin/env php /some/other/dir/script.php