Archive for the ‘PHP’ Category

Useful PHP Resources

Past few months, I have seen a lot of people asking for sites that teach php from the ground up. So, here are a couple of places you can go to learn php from scratch. http://www.addedbytes.com/php/php-cheat-sheet/ Learn PHP Free.com PHP.net – Start melonfire.com http://codewalkers.com/ Free 2 code http://forums.devnetwork.net http://www.objectgraph.com/dictionary/php.html http://www.gotapi.com/html http://dev.mysql.com/usingmysql/php/ You know, i am [...]

Pull any RSS feed, Show link, Title and Date and Shorten Date and Title

This is modified and expanded version of http://net.tutsplus.com/articles/news/how-to-read-an-rss-feed-with-php-screencast. <?php function shorten($string, $length=65){ $truncated_string = ”; foreach (explode(‘ ‘, $string) as $word){ if (strlen($truncated_string) >= $length){ return $truncated_string; } $truncated_string .= (!empty($truncated_string) ? ‘ ‘ : ”) . $word; } return $truncated_string; } function getFeed($feed_url) { $content = file_get_contents($feed_url); $x = new SimpleXmlElement($content); echo “<ul class=’rss-feed’>”; [...]

IP2Country PHP Class

This class can be used to get information of the country of an IP address. It takes an IP address and queries MySQL database to determine the country associated with the given IP address range. The class returns the associated country name and country codes with both 2 and 3 letters. You can get more [...]

Store Daily Alexa Report into MySQL using PHP Simple HTML DOM Parser

My company asks me to take daily alexa report manually. I took for more than 3 months. But, after that, i got bored in doing manual works. Becuase, nearly i needs to take more than 20 websites per day. It’s eats my time and structs in my remaining works. So, i searched for solution online [...]

Log into the Google Analytics API using PHP and CURL using Username/Password Authentication

Google have finally made an API available for Google Analytics although it’s currently in beta and the specs are subject to change. I’ve been playing around this morning logging in using ClientLogin Username/Password Authentication with PHP and CURL and show how to do this here. The code example below attempts to log in using $email [...]

Use isset() Instead of strlen()

This is actually a neat trick. Here is the example: <?php if (isset($username[5])) { // The username is at least six characters long. } ?> When you treat strings as arrays, each character in the string is an element in the array. By determining whether a particular element exists, you can determine whether the string [...]

Shortcut the else in PHP

This tip accidentally stumbles upon a useful practice, which is to always initialize variables before you use them. Consider a conditional statement that determines whether a user is an administrator based on the username: <?php if (auth($username) == ‘admin’) { $admin = TRUE; } else { $admin = FALSE; } ?> This seems safe enough, [...]

Know the Difference Between Comparison Operators

This is a good tip, but it is missing a practical example that demonstrates when a non-strict comparison can cause problems. If you use strpos() to determine whether a substring exists within a string (it returns FALSE if the substring is not found), the results can be misleading: <?php $authors = ‘Vijay & Jana’; if (strpos($authors, ‘Vijay’)) [...]