2010

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: Export Table to CSV Text Files for Excel

MySQL tables can be exported to SQL dump file which is basically a text file of SQL queries that can be used to import the table back into database. To export MySQL tables into other formats such as CSV, phpMyAdmin proves to be very handy if you have changed the execution timeout in seconds to …

MySQL: Export Table to CSV Text Files for Excel 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 »

PHP: Get Human Readable Time from Seconds

Linux timestamp is a number of seconds from the Epoch of Linux, large number of seconds. When you are counting the time interval between 2 times or 2 dates, the result is usually in seconds as well. Understandably, it’s everything but user friendly to just present the number of seconds to the users, e.g. 153297 …

PHP: Get Human Readable Time from Seconds 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 »

Regular Expressions for Natural Numbers or Positive Integers (1, 2, 3, …), Negative Integers and Non-negative Integers

When I’m developing the online form creator that enables the users to create form fields that accept only certain type of numbers, I need to verify if a given string is a valid natural number such as 1, 2, 3, 4, …. I’m writing the code / functions in PHP but you can literally use …

Regular Expressions for Natural Numbers or Positive Integers (1, 2, 3, …), Negative Integers and Non-negative Integers Read More »

PHP: True empty() function to check if a string is empty or zero in length

The strange thing is that the native empty() function of PHP treats a string of ‘0’ as empty: $str = ‘0’; echo empty($str) ? ’empty’ : ‘non-empty’; And it will output ’empty’. Therefore if you need to examine if a string is truly an empty string with zero length, you have to use: echo strlen($str) …

PHP: True empty() function to check if a string is empty or zero in length Read More »

Auto-generated content by user searches

A not-so-commonly employed content strategy is to automatically generate custom content by user searches. For example, if you’ve got a popular blog, there will be a lot of users searching for things they want to find on your blog. It’s an obvious sign that they want you to write about them. While you are recommended …

Auto-generated content by user searches Read More »

PHP: Checking Text Strings against Reserved or Censored Words

I created a free online web form builder a while back and since it went well in search engine rankings, spammers and phishers found it and started to use it creating forms to collect email account usernames and passwords through phishing attempts. I’ve got to do something before my host closes down my site because …

PHP: Checking Text Strings against Reserved or Censored Words Read More »

How to create / generate .htpasswd password with PHP dynamically?

The easy way to add a username and password pair in the .htpasswd file is to use an online password generator tool that converts the clear text password into its hash, a.k.a. the encrypted password. The problem with this approach is that you have to manually create the pair and append it to .htpasswd. Is …

How to create / generate .htpasswd password with PHP dynamically? Read More »

Check how much memory your PHP script is using. (PHP script memory usage)

Depending on the web server software you use, your PHP script will be consuming significantly different amount of memory (RAM). If you are using Apache without proper optimization, the simplest request that does nothing but returns a status code will need 150kB of memory. Multiply this by 2000 visits per day and by 10 sites …

Check how much memory your PHP script is using. (PHP script memory usage) Read More »

Shady GoDaddy: How to cancel private registration for your domain renewals?

If you accepted GoDaddy’s offer of the first-year-free private registration service for your domain, you would not be so happy when you are renewing the domain for more years because you will find the private registration is bound to that domain. You can either renew the domain WITH the private registration which costs an extra …

Shady GoDaddy: How to cancel private registration for your domain renewals? Read More »

How to hide and force the visitor to click your referral or affiliate link?

There are primarily 2 ways for merchants to set up an affiliate program, one is to offer coupons that are assigned to the affiliates and can be spread out. When someone uses that coupon, the merchant knows it’s a referral by that affiliate. The other is to create dedicated links with the affiliate ID in …

How to hide and force the visitor to click your referral or affiliate link? Read More »

MilitaryFictionBooks.com and StandingDesk.org Status Report

MilitaryFictionBooks.com is actually an old domain, I registered it over a year ago and parked it ever since with a custom page of my own. It has been indexed in Google for 1 year. So what you are seeing now may very probably not happen for you if you just registered a fresh domain name. …

MilitaryFictionBooks.com and StandingDesk.org Status Report Read More »

Scroll to Top