I am Hack Sparrow
Captain of the Internets.

Check object type in PHP

Been working on something where you need to check the type of PHP objects? Doing that is pretty straightforward. In fact, there are two ways to do it, I'll show you both. You know there are predefined object types in PHP, you just call the is_* functions to test. The following code shows you how to do the _is* testing. is_nul ...

Email validation Regex in PHP

Here is a good regex in PHP which will help you validate a vast number of possible emails, also it is case-insensitive. Useful for checking if an input is a valid email or not. [code] /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/i [/code] Below is an example in PHP which validates the va ...

PHP CURLOPT_GET Does not Exist!

Sooner or later someone's going run into this notice error: Use of undefined constant CURLOPT_GET - assumed 'CURLOPT_GET'. Probably you downloaded a PHP class or a function written by someone else from the Web. Right? Well, no matter how you ended up with that notice, let's try to analyze the problem and the solution. Take a look at the example code: [php] curl_setopt($ch, CURLOPT_GET, true); [/php] We can safely as ...

PHP: How to remove Numbers from String

For whatever reason if you are looking to remove all instances of numbers from a string in PHP, use the simple function I deviced below. [php] function remove_numbers($string) { $num = array(1,2,3,4,5,6,7,8,9,0); return str_replace($num, '', $string); } [/php] Examples of using the number removing function. [php] echo remove_numbers('123kicks'); //echoes kicks echo remove_numbers('0t4r45i34c525k345s983!4 ...

How to Generate Compressed XML Sitemaps Using PHP

So you figured your 5 mb-and-growing dynamically generated XML sitemap has been a major bandwidth hog and are scared it might bring your website  on its knees; or maybe you wanna play nice with Google by serving it a fast loading compressed XML sitemap. Whatever be the reason, you are here to find out how to compress your xml sitemap and output it as a .gz file, something like sitemap.xml.gz. Compressed XML Sitemap ...