Categories
PHP

Read a Word doc using COM

So I managed to write a script to read a Microsoft Word document using PHP CLI and the COM object pretty easily, but then battled to get it working in the browser. In your php.ini: ; allow Distributed-COM calls; http://php.net/com.allow-dcomcom.allow_dcom = true On your Windows PC: Run “dcomcnfg” (right-click Windows icon and select Run) to open […]

Categories
PHP

PHP Dynamic year selector

Another post from the archives. After 2009 rolled in and all our sites failed to follow suite because  “someone” hard-coded the years – but only up to 2008 – I quickly had to write something a bit more – well, smart. I needed an HTML drop-down box with a set of years starting from a […]

Categories
PHP

PHP CLI “Hello World”

I have only recently begun working with PHP CLI scripts. Executing PHP scripts from the command line is fairly easy and you require no extra knowledge to create a basic script. As you progress you will need to know some new methods of using PHP. Below is a PHP script called hello.php which is executed […]

Categories
PHP

PHP short tags

Another post from the archives: I am running a WAMP development environment at home and at work. I am always looking for new ways to fine-tune my set-up. Here is one… The short open tags option allow you to leave off the “php” in the opening tag of your code block. So, instead of: <?php […]

Categories
PHP

PHP / MySQL: storing database credentials in an .ini file

It is recommended that you do not include database connection details in your scripts, so where exactly do you store them? Luckily, PHP has the handy function parse_ini_file() specifically for this task. From php.net: parse_ini_file ( string $filename [, bool $process_sections = false [, int $scanner_mode = INI_SCANNER_NORMAL ]] ) The $process_sections parameter allows you to […]

Categories
Heroku

Heroku: getting started with PHP

So I started out with the Getting Started for PHP on the Heroku site in my efforts to get into the cloud. The step-by-step guide on the Heroku site is fairly straight forward. I made the following notes (I am using Windows 10): You will need Composer – I used the Composer-Setup.exe – you will need […]

Categories
JavaScript

Google Code Prettify

I have played with various WordPress plugins for code syntax highlighting, but recently helped answer a query with regards syntax highlighting in other projects using Google Code Prettify. If you store your code samples in a MySQL database, the trick is to store them as html entities. In other words, the following PHP code: <?php //comment […]

Categories
PHP

Bar-code generator for PHP

Whilst fiddling around with QR Codes, I came across this Bar-code generator for PHP. Minimum requirements: PHP 5 GD2 Extension Here is my code for a basic implementation (adapted from the manual which has errors): <?php require_once(‘class/BCGFontFile.php’); require_once(‘class/BCGColor.php’); require_once(‘class/BCGDrawing.php’); require_once(‘class/BCGcode128.barcode.php’); // The arguments are R, G, and B for color. $colorBack = new BCGColor(255, 255, […]

Categories
PHP

E-mail address validation

Hoo boy we have to do this all the time and a quick Google tells me everyone has their favorite little tricks. Some even work. Here are the results of an exercise in e-mail validation using two different PHP options, namely: filter_var($email, FILTER_VALIDATE_EMAIL)); preg_match(‘/^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*\@([a-z0-9])*(\.([a-z0-9])([-a-z0-9_-])([a-z0-9])+)*$/i’, $email); See demo page here…

Categories
PHP

Upload PDF script

This was a quick hack to upload a PDF to Clearer Conscience. This script was a quick hack to allow a PDF to be uploaded to replace an outdated one on Clearer Conscience. As the PDF link on the site is hard-coded, the new PDF must have the same name as the old one. You […]