Integrating social media into your application, part 2
August 26, 2009 | No Comments
To continue in this series, I will discuss using the bit.ly URL shortening service API.
I’ve already created a function for updating my Twitter status, but what if I need a shortened URL?
Here’s the code:
// URL shortener function
function shortUrl($longURL) {
$long_URL_recode = (stristr($longURL, "+")) ? str_replace("+", " ", $longURL) : $longURL; // if necessary, reformat URL, replace + with space
// bit.ly api url
$api_url = "http://api.bit.ly/shorten?version=2.0.1&longUrl=" . $longURL . "&login=mybitlylogin&apiKey=mybitlyapikey&history=1";
// get data from bit.ly api
$ch = curl_init($api_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$curl_data = curl_exec($ch);
curl_close($ch);
// get short url from decoded curl data
$curl_data_decode = json_decode($curl_data);
$shortURL = $curl_data_decode->results->$long_URL_recode->shortUrl;
return $shortURL;
}
To explain in more detail:
- First, we clean up the URL. Because we don’t necessarily know the form of the URL we’re providing, we make sure that we replace any potential spaces with the plus (+) sign.
- Now we set the bit.ly API URL, which includes the long URL, the bit.ly login name and API key, as well as the option to store the link in our bit.ly link history. (You’ll need a bit.ly account.)
- We initialize the cURL session, set the option to get the returned data, execute than close the session.
- Finally, we get the shortened URL from the parsed JSON string.
- This is where the recoded long URL comes into play. We could have waited until this point to recode the URL.
Pretty simple. I can add this function to any application where shortened links may come in handy.
Next in this series: getting recently played tracks from last.fm.
Tags: application development > cURL > Facebook > PHP > social media > social networks > Twitter > web development
Learning PHP
August 24, 2009 | No Comments
By: Andy Johnson
PHP is the world’s most popular web development language. Started by Danish-Greenlandic programmer Rasmus Lerdorf in 1995 it is now installed on more than 20 million websites and 1 million web servers and counting.
It is estimated that for every 100 PHP developers, there are 42 Perl developers, 12 Python developers and 4 Ruby developers – PHPs popularity is the central reason why you should consider learning it above all others.
PHP is the basis of Content Management Systems such as Drupal, Joomla and WordPress so gaining a knowledge of PHP would help you in using these scripts.
Presumably your are already proficient with CSS and HTML and want to take your web creativity to another level. If you aren’t, then stop right here. It’s unthinkable to tackle PHP without a firm grounding in HTML and a good knowledge of CSS would be extremely useful.
You don’t have to have a complete knowledge of HTML in order to learn PHP but you certainly need to know the basics – the rest you will pick up in tandem with PHP. For instance, if you use Content Management Systems all the time you’ll unlikely to be that familiar with coding forms, but HTML forms are an essential part of PHP and you’ll need to be able to create them quickly and without fuss.
Learning PHP is as hard as you can imagine it to be. You need time and lots of patience and preferably a reality you need to escape from for an inordinate amount of time. It’s a good idea to pace yourself and set a two year framework in order to become familiar with the core of the language.
Prepare yourself for headaches and frustration and a slow, boring learning curve as it’s on about the same thrill level as a crossword or Sudokus puzzle.
You must be familiar with the multitude of Photoshop net tutorials out there – you know, the ones that engage you with a step-by-step guide and lots of pretty pictures. Well there is nothing comparable in PHP.
It may be unfair to compare photo manipulation software to a programming language, but even the Ruby crew manage to add a bit of bling to their learning process.
Of course, there is satisfaction at creating your first form or web application – to actually create a working item is a tremendous achievement when you are starting out.
So what makes a good PHP programmer? It is the ability to write effective, secure code quickly. Effective means using as little code as possible for the task at hand as well as learning which code is the least wasteful on your server resources (this is technically called refactoring). Secure means that your code is as safe as possible from malicious users and crackers.
To be a quick PHP coder means that you have a thorough knowledge of the syntax and functions as well as library of code which you have created and testing on live websites and that you can bring into new web developments.
You’ll often read a reference to “clean code” amongst PHP heads (and all other code writers for that matter) and above is essentially what they mean by this term.
If you really want to learn PHP though I can guarantee one thing: that you will succeed if you have enough time and are determined enough.
Nobody is born to code PHP – expertise will come about through you applying yourself.
About the Author:
Andy Walpole is a web designer and developer and can be found at Suburban Glory Web Design.
Article Source: ArticlesBase.com – Learning PHP
Integrating social media into your application, part 1
August 22, 2009 | No Comments

By: Craig McNaughton
This post (with a different title) was originally going to be about how I use social media and social networks to promote myself and my brand, but this is a web developer’s blog and you guys want to hear about web development. So I’m actually going to post, in several parts, my web development strategy for social networks.
I was getting tired of relying on other people’s Twitter automation, and on my own repetitive Twitter tasks, so I developed a solution using the Twitter API. Here’s the code:
<?php
// send status update to twitter
function tweet($twitter_status, $twitter_user, $twitter_password) {
// set Twitter tweet data
$twitter_api_url = "http://twitter.com/statuses/update.json";
$twitter_data = "status=" . urlencode($twitter_status);
$ch = curl_init($twitter_api_url); //initiate cURL session
// set cURL options
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $twitter_data);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERPWD, "{$twitter_user}:{$twitter_password}");
$twitter_response = curl_exec($ch); // get cURL response
$http_response = curl_getinfo($ch, CURLINFO_HTTP_CODE); // get HTTP status
curl_close($ch); // close cURL session
if ($http_response == 200) { // good Twitter response
return $twitter_response;
} else {
return false;
}
}
?>
To explain the code in some detail:
- We start by setting the Twitter API URL and the Twitter status text. This is basically an HTTP POST request, hence the urlencode().
- Next, we initiate the cURL session and set some options. Take a look at the cURL manual for more information.
- Third, we get the cURL response and the corresponding HTTP status code, then close the cURL session.
- If the HTTP status is 200 (OK), then the tweet was successful and the full Twitter response is returned.
Simply put, this function takes my Twitter status text, username and password and returns a JSON string that can be easily parsed using the json_decode function. I can supply the status text from a submission form, a database or even a text file.
Any questions? Let me know.
Next in this series: using the bit.ly URL shortening service API.
Tags: application development > cURL > Facebook > PHP > social media > social networks > Twitter > web development
CSS Table Less Format and HTML Table Base Format, Which One You Prefer
August 18, 2009 | No Comments
I have been doing extensive research on net regarding people’s opinion on building website using CSS div based format over HTML table based format and have found that there is a lot more improvement in terms of page size, load time and search engine positioning after switching to CSS div based format.
CSS is syntactic, it’s fast and lightweight. Compared to HTML, developing a site in CSS table less format is more systematic. The clarity of the code in CSS makes you feel much in control where as in HTML table based format we just go on pumping the tables into the design leading to more complex and cluttered html code. CSS is definitely more of an efficient way to code, as the style sheet is loaded once and cached, versus loading the table code with every page.
Depends on how complicated website design is I would recommend CSS over HTML. In CSS the basic principle is to use div tags as containers to hold different elements instead of table cells. Assigning an id or class to those div allows you to add styles and to position them using an external style sheet instead of over and over again in each td. Many times instead of going for 100 percent CSS table less development people use partial CSS div based and partial HTML table based procedure. For e.g. They use a table for holding things in place and assign ids or classes to the tds for styling, which is still better than a purely table based design with inline styles.
As far as code goes, we all know now that CSS generates less code and it is search engine friendly but it has certain limitations and problem, often it is because of browser incompatibility. I’ve seen lots of website layouts done with CSS, where the content breaks the layout and boxes overlap each other, making certain parts of the content unreadable. Such things are easily manageable using tables where as CSS would require multiple “hacks” to produce the desired outcome.
Redesigning a CSS div based site is much easier and less time consuming than HTML table based site. This is because CSS designs have separate files for content and visual data including web page structure whereas table based designs mix layout information with content in the same file. Table based HTML sites heavily relay on spacers (transparent gifs) to control blank spaces within the sites, where as this can be easily achieved using margins and padding in CSS layout.
Although CSS based design appears to be simpler, neat and tidy you need to spend significant amount of time learning the rules of the CSS. This comes through practice only. If you want to make pure CSS div based designs, be prepared to invest time in learning. No matter how seasoned developer or designer you are, be prepared to hunt down the bugs relentlessly for endless hours.
Web developers must consider their clients preference before finalizing the format. If the client is more concerned about standards and wants to be sure not to use any deprecated strings in their webpage then CSS div based design is the best option.
Finally we can say let the war continues between CSS div based and HTML table based design to our benefit. In the mean time designers and developers can add on more knowledge and practice with both tables and CSS and become more versatile to handle any situation.
About the author
Vaishali Kapote works with WebsiteDesign.in, a unique and creative design studio providing Custom website design & Graphic design services for Branding, Web, Application development, Interactive, Print, Programming, and Specialty projects.
Article Source: http://EzineArticles.com/?expert=Vaishali_Kapote
http://EzineArticles.com/?CSS-Table-Less-Format-and-HTML-Table-Base-Format,-Which-One-You-Prefer&id=2306045
Tags: css > css-based layout > HTML > table-based layout > table-less layout
By