Programming Tips & Insights

PHP: Check if A String Contain Only Uppercase / Capital Letters

Sometimes you would want to check if a string is an acronym or an abbreviation by testing if it only contains capitalized letters from A to Z and nothing else. There are 2 ways to accomplish this simple task in PHP. ctype_upper() Use the native ctype_upper() function and you will know if the provided string …

PHP: Check if A String Contain Only Uppercase / Capital Letters Read More »

FFVCL – FFmpeg Delphi VCL for Video / Audio Apps Development

This post is dedicated to one of my friends, Coolie (not his real name but he preferred to be called that way among friends), a father and self-entrepreneur who created the outstanding Delphi VCL component for FFmpeg that makes it extremely easy to develop audio and video applications for Windows. For those who are not …

FFVCL – FFmpeg Delphi VCL for Video / Audio Apps Development Read More »

PHP: Crontab Class to Add, Edit and Remove Cron Jobs

Provided that your user account on the server has the privileges to access crontab thus can create or remove cron jobs, you can use this PHP class to integrate crontab in your application. I created it for many of my own projects that need crontab to do scheduled jobs. It’s pretty straightforward. Don’t know what …

PHP: Crontab Class to Add, Edit and Remove Cron Jobs Read More »

PHP: Display Files and Sub-directories of A Directory Recursively as A Tree

Given a directory, how to display the contents (directories and files under it) of it recursively and exhaustively? Here’s the code: $dir = ‘/path/to/directory’; // without trailing slash, can be absolute paths such as ‘/home/jim/public_html’ or relative paths such as ‘samples’ getDirContents($dir); function getDirContents($dir) { if (is_dir($dir)) { $dirs = explode(‘/’, $dir); $last_dir = $dirs[count($dirs) …

PHP: Display Files and Sub-directories of A Directory Recursively as A Tree Read More »

MySQL: Get the exact size of a database by SQL query

phpMyAdmin doesn’t show the exact size in MB when the size of your database exceeds 1GB. It just shows something like 4.2GB, truncating everything out in the 100MB precision. So is it possible to get the database size in MB in exact numbers using MySQL query? Yes, it is: SELECT CONCAT(sum(ROUND(((DATA_LENGTH + INDEX_LENGTH – DATA_FREE) …

MySQL: Get the exact size of a database by SQL query Read More »

MySQL: How to export a database / table to XML?

You can export any MySQL database or table into an XML file by the exporting capabilities of phpMyAdmin, the web interface of MySQL. The problem with this approach, however, is that with large tables, you may have to manually export the table more than once by sections into several sequential XML files. A better approach …

MySQL: How to export a database / table to XML? Read More »

Checklist slides to learn the new features in PHP 5.3 with examples

One of my old Internet friends Brad made a very nice online slide that introduces to you some of the exciting new features of PHP 5.3. I’m most interested in namespace that would make coding in a large project and code reuse much easier, especially for people who find keeping naming conventions a challenge in …

Checklist slides to learn the new features in PHP 5.3 with examples Read More »

A small mistake in a regular expression caused connection to reset – (.+)+

Was doing something with a regular expression and very oddly the connection keeps being reset every time I refresh the web page. I tried to narrow down the problematic line by removing the code in functional chunks. Finally it comes down to a preg_match() instance with a small bit in the regular expression that’s accidentally …

A small mistake in a regular expression caused connection to reset – (.+)+ Read More »

MySQL log files are taking a lot of disk space – How to disable and delete them?

I have WAMP server installed on my local computer for PHP and MySQL development. After using it for a while, the MySQL installation folder has run up some seriously huge log files that are taking enormous amount of disk space. We are talking 10s of GB here. The file names are like ibdata1, mysql-bin.000017, etc.. …

MySQL log files are taking a lot of disk space – How to disable and delete them? Read More »

MySQL: Change Default Character Set or Default Collation in phpMyAdmin

It can be annoying when MySQL imports your UTF8 database (which contains exotic characters other than those in English) in the default character set of latin1_swedish_ci, jeopardizing the text content. It is also annoying when phpMyAdmin does the same and when you forgot to set the collation to utf8_general_ci for the new database which is …

MySQL: Change Default Character Set or Default Collation in phpMyAdmin Read More »

Regular Expression for Date and Time Strings

Often we need the users to enter a valid string of date or time in the form. But how do you validate the strings with regular expressions? In PHP, you can use these functions and regular expressions. RegExp and function to validate against date string: // Default: YYYY-MM-DD function isDate($subject, $separator = ‘-‘) { return …

Regular Expression for Date and Time Strings Read More »

Scroll to Top