Read a file into an array
Here's something that puddled me for a while...
$filename = 'file.txt';
$file_handle = fopen($filename, 'r');
$data = '';
while(!feof($file_handle)){
$data .= fgets($file_handle, 1024);
}
Converting XLS to CSV. Simple, eh? Well, sorta.
I hate problems that can be solved really easily. (With a totally different set of tools). I needed to open Excel (XLS) files in PHP. Simple enough you think, IF you are using Windows.
IF I was using Windows, I would have a bunch of options open to me, I could use PHP's COM & .NET functions. Or PHP's ODBC functions. Or a selection of classess from PHP Classes.
NTLM Authentication (Active Directory) on Apache (Linux)
Here is a quick guide to enabling NTLM authentication for Apache 2.
I generally use Ubuntu, so I am a heavy apt-get'er, but I prefer to build my apache from source.
Apache2 mod_deflate
The mod_deflate module provides the DEFLATE output filter that allows output from your server to be compressed before being sent to the client over the network.
Lazy man's description, your pages load quicker.
Card Reader Annoyances
My new Dell computer came with one of those 1,600 in 1 internal memory card readers. The 1,600 drives in 'My Computer' really irritated me.
OK, so I exaggerated slightly. But the extra 3 drives did irritate me. My cameras use SD cards so I can safely disable the ones I don't use.
Apache, JungleDisk and Port 80
I was tearing what little hair I have trying to solve a very strange bug on Windows with Apache 2 & JungleDisk.
(Yes I use Amazon's Simple Storage Service for all my backups).
I was getting the following errors in Event Log, for what appeared to be no reason.
The Apache service named reported the following error:
>>> (OS 10048)Only one usage of each socket address (protocol/network address/port) is normally permitted. : make_sock: could not bind to address 0.0.0.0:80 .
The Apache service named reported the following error:
>>> Unable to open logs
file_exists(), is_file() & is_dir() with spaces?
Why won't file_exists(), is_file(), is_dir() return true if the file or directory has a space in it?
I spent a few hours trying all kinds of ways to make this work. I finally settled on using $file->setName("safe"); from PEAR's HTTP_Upload class which makes the uploaded file "safe".
What's safe?
Yellow text?
I stumbled over a strange bug on two systems the other day where the imagettftext() function was always writing the text in yellow. No matter how I set the colour, imagecolorallocate($image, 0, 0, 0);, I would always get yellow. Why yellow?
Both systems are Ubuntu, I don't know if it is a mix up on the libraries from the package, or indeed PHP.
I had to recompile PHP ignoring the --with-ttf option which most docs suggest, and just use the --with-freetype-dir instead. Problem solved.
“Mail option not available!”
I spotted a strange PHP "feature" in the error_log() feature.
PHP checks for sendmail functionality once during ./configure for the mail() and error_log() functions.
Now, you can quite happily pass the sendmail path with the 'additional_parameters' flag to the mail() function, if you added mail support later but error_log() won't take that flag, so it fails with "Mail option not available!"
Rule: Install postfix/qmail/whatever BEFORE installing PHP if you want to use mail as an error_log() option.