Author name: Yang Yang

Hello, I'm Yang. I build online businesses that please people. Want to join in and post some useful articles on Kavoir.com? Shoot me a message.

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 »

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 »

Amazon Associate (Affiliate) Program Review: Why I love them

Go to Amazon.com: http://www.amazon.com There are tens of thousands of different affiliate programs out there you can use to monetize your traffic. A few of the biggest players are ClickBank, eBay, Amazon, CJ and Google Affiliate Network. Unlike CJ and Google Affiliate Network who are simply brokers of merchants and affiliates, Amazon and eBay are independent …

Amazon Associate (Affiliate) Program Review: Why I love them Read More »

Godaddy $7.69 .org domain registration coupon promo code

Update: Here’s the latest coupon code of Godaddy – $1.49 / year .com God knows why they have raised the .org registration fee to $14.99. I don’t know if it’s temporary or just the way it will be for a long time to come but it’s outrageous. Fortunately I have found this .org domain registration …

Godaddy $7.69 .org domain registration coupon promo code Read More »

How to get all the sub-directories of a given directory in PHP?

When you read the content of any specified directory with PHP functions such as scandir() or readdir(), they will return both files and directories. How does one get just the child directories of a given directory in PHP? The obvious solution is the is_dir() function that checks if a filename is a directory: $all = …

How to get all the sub-directories of a given directory in PHP? Read More »

How to check if a MySQL database connection is successful in PHP?

If you have mysqli extension installed with PHP and you use it to perform database operations, after you have tried to connect to MySQL by: $conn = new mysqli(‘localhost’, ‘db_user’, ‘db_pwd’, ‘db_name’); You can then check if the connection is successful by: if ($conn -> connect_errno) { // failure } else { // success } …

How to check if a MySQL database connection is successful in PHP? Read More »

How to include a JavaScript file inside a JavaScript file?

This is a pretty odd question to ask in the first place if you have been using JavaScript for a while. JavaScript files are called from HTML web pages who need them to manipulate the HTML elements so that the users have extraordinary interactive experience. You can’t include a JavaScript file inside another JavaScript file …

How to include a JavaScript file inside a JavaScript file? Read More »

Scroll to Top