 | News Feed |
 | Jobs Feed |
Sections
|
| feed this: |  |
Paul Gregg's Blog: "tail -# file" in PHP
by Chris Cornutt April 24, 2009 @ 12:02:42
Paul Gregg has written up an example of what he calls "tail -# file for PHP" (starting from the end of file and moving backwards a given number of lines).
Here I will demonstrate a fairly tuned method of seeking to the end of the file and stepping back to read sufficient lines to the end of the file. If insufficient lines are returned, it incrementally looks back further in the file until it either can look no further, or sufficient lines are returned.
His script meets two goals - reading enough lines in for the request and keeping those lines to a minimum. His code grabs the size of the file and opens the file as a resource to fseek to a certain point and read in the lines from the defined start to finish and push them into an array. You can see the source here and a sample execution here.
voice your opinion now!
tail log file fseek example read
PHPro.org: Read Line From File (stream_get_line)
by Chris Cornutt April 23, 2009 @ 09:36:51
The PHPro.org website has a quick new tutorial about a method (using streams) to get the information from a certain line of a file.
Reading files in PHP can be a tricky business if not handled correctly. Most often when confronted with reading a line from, the nearest tool to hand is the file() function. The problem with using the file() function is that it reads the whole file into an array, and thus, into memory [...] A better, and more efficient way is to loop through the file stream using the stream_get_line() function. Care still needs to be taken to clear the buffer on each iteration, or the same problem could potentially arise as with the file() method.
The code calls fopen on the file and, while it's not the end of the file, uses the stream_get_line function to grab things a line at a time. This saves you from having to read in the entire file (like with a file_get_contents or file - especially good for large files.
voice your opinion now!
stream tutorial file line read streamgetline
TotalPHP.com: How to Read an RSS Feed with PHP 5
by Chris Cornutt April 22, 2009 @ 11:15:16
New on the TotalPHP blog today is this article talking about reading RSS feeds with PHP (more specifically with SimpleXML).
PHP 5's ability to read XML files is fantastically easy to use. In the past it was possible but it required quite a bit of long winded code to get any where. PHP 5's SimpleXmlElement function makes working with XML a breeze, and with much less code too!
They include a script as an example - five lines to completely parse and pull the title and link information out of the remote RSS file. The example creates a SimpleXML object using the feed's URL and makes each element inside accessible as an object (that can be looped through and properties can be checked on).
voice your opinion now!
title link object example simplexml php5 read rss
Zend Developer Zone: Reading Access Databases with PHP and PECL
by Chris Cornutt November 26, 2008 @ 13:26:12
The Zend Developer Zone has a new tutorial posted today from Vikram Vaswani about accessing a database with the help of the MDBTools PECL extension to read from a Microsoft Access datbase.
In this article, I'll introduce you to PHP's MDBTools extension, which provides an API to programmatically read data from Microsoft Access database files. If your project involves working with such files, extracting database records either for calculations or for conversion to other formats, you'll find this extension invaluable.
He steps through the installation of the extension (via the pecl command line tool) and some sample code that grabs the tables, all of their attributes and how to select the data out from them.
voice your opinion now!
read database tutorial msaccess microsoft access pecl extension mdbtools
SitePoint Web Tech Blog: How To Create Friendlier Random Passwords
by Chris Cornutt November 13, 2008 @ 07:55:59
New on the SitePoint "Web Tech" blog today is a post by Craig Anderson about friendlier passwords.
One aspect of web applications which is almost always overlooked when it comes to accessibility is how easy any randomly generated string might be to read. If you're lucky enough to have near perfect vision and have no learning or cognitive disabilities such as dyslexia, you mightn't suffer from any problems reading randomly generated strings, but for many users distinguishing between zero and upper-case Os, ones and lower-case Ls, and even the letters b and d can be difficult.
He includes a simple little PHP script that pulls letters and numbers from a pre-defined "friendly" array that can be read more easily by those with some sort of visual issue. Obviously, the results would be less secure than some other methods (only so many to go around) but its still a wide enough range for most common uses (around 17 million passwords).
voice your opinion now!
friendlier random passwords tutorial example visual read easy
Bryan's Blog: 5 (More) Ways to be a Better PHP Developer
by Chris Cornutt February 14, 2008 @ 12:53:00
Following up on this article from Akash Mehta, Bryan has posted five more suggestions he has to help make you a better PHP developer.
I thought all of Akash's suggestions were good but a little broad and seemed to involve a lot of reading. And while any budding developer will jump at the chance to expand their burgeoning technical library, I thought there were a couple of items we could add to his list.
The recommendations that made his list are
- Start a project that other people (developers and end users) will use.
- Learn another language.
- Teach someone PHP.
- Ask for suggestions not solutions.
- Use what you read.
I'm particularly a fan of the third one (teaching) - not only does it spread PHP out even more through the masses, but it can really test you on your knowledge (some of those "how do I.." questions can get a bit complex, even from beginners).
voice your opinion now!
better developer suggestion list teach suggestion read project language
|
Community Events
Don't see your event here? Let us know!
|