摘要： 本文讲的是A Quick Tip For Reading Files with PHP， If you’re in the business of building plugins – regardless of if it’s for fun or profit – the odds that you’re eventual
If you’re in the business of building plugins – regardless of if it’s for fun or profit – the odds that you’re eventually going to have to read the contents of a file are relatively high.
This could be for importing data from a file, this could be for parsing data out of something that a customer has provided, or this could just be used to help drive the user interface. Whatever the case, PHP offers a number of different functions for opening files and reading files.
This can be convenient, but in my experience, there’s one process that I’ve found to be more resilient than the other options when it comes to reading files and I thought I’d share the general process here.
When it comes to reading files with PHP, it’s a six step process (though a very simple set of six steps):
Note that thereareother functions likefile_get_contentswhich can read the entire contents of files into a variable, but in all of the work that I’ve done, using the method described above not only proves to be the most reliable when reading files, but also the most convenient (since it allows me to determine how I want to open the file – for reading, writing, how much of the file to read, etc.).
For more information, be sure to check out thefreadpage in the PHP manual; otherwise, I hope this method is useful in future work that you may be doing in WordPress or just in PHP in general.
|php pear-apt-get 安装p...||如何用 php 从 .jpg 图像中读取...||Script Caching with ...|
|... root@dev:/# sudo apt-get install php-pear Reading ...||...firstname.lastname@example.org 21-Aug-2001 11:43 Perl Image::In...||...ads the dynamic script URL using fread(), just as i...|