Archive for the 'Tutorial' Category

How to generate PDF from XHTML or XML source using a Java Applet

Here is an example on how to use a Java Applet to generate a PDF from XHTML or XML source. The main advantage of using an Applet to generate from XHTML or XML source is XHTML/XML source can be gzip compressed from the source web server which reduces very much its size to be transferred over a slow network connection and is speedier, while compared to an actual PDF file that’s transferred over the same network.

Continue reading ‘How to generate PDF from XHTML or XML source using a Java Applet’

How to get the country of an IP address in PHP?

The HostIP.info provides API allows you to get the country including the city as well. The simple PHP script that can get the country is as follow:

Continue reading ‘How to get the country of an IP address in PHP?’

Google Chart API example : Display data on chart made easy

The Google Chart API provides an easy way to generate a chart dynamically by sending a simple URL to Google Chart service as follows:

http://chart.apis.google.com/chart?cht=p3&chd=t:60,40&chs=250×100&chl=Hello|World

And Google Chart returns you an image of the chart. As shown the above you just need to pass the Google Chart with three parameters, which are cht (Chart Type), chd (The percentage distribution of your data on Chart), chs (Chart size), and the chl (Chart Label)

Continue reading ‘Google Chart API example : Display data on chart made easy’

Google Gears Geolocation API, example displays your location on Google Map

The Google Gears Geolocation API allows you to display your current position data by obtaining it from your WiFi antenna. The Google Gears Geolocation API is able to obtain the exact location of the user’s current location, in terms of latitude, longitude and even the address etc. User browsers such as Internet Explorer, Firefox must have Google Gears installed excepts Google Chrome, in order to have the Google Gears API to work on your browser.

Continue reading ‘Google Gears Geolocation API, example displays your location on Google Map’

To validate if an URL exists, use PHP CURL

PHP Curl allows you to validate if a given URL exists. What you need to do is just a simple function as follows, which takes an input URL and returns the code. If the returned code is 200, then the URL exists, else it doesn’t!

Continue reading ‘To validate if an URL exists, use PHP CURL’

How to shorten long URLs in a user-input text by using TinyURL programmatically

TinyURL allows long URL to be shortened. In this example, I’d like to show how you can build a text form that contains text keyed in by a user, and sends to the server-side PHP to detect those overly long URLs and shorten them one by one by sending them to TinyURL service.

Before I proceed, I’d like to let you know that TinyURL has an API, which is as follows and it returns a single string only that is the tiny url which has been shortened from the given “url” parameter.

Continue reading ‘How to shorten long URLs in a user-input text by using TinyURL programmatically’

Sorting data made easy using JavaScript table sorter

javascript-table-sorter
If you’re asked to build a PHP script that pumps out some data from the database and presents in an HTML table to the users. And on the first row of the table, shows the titles of each field (As pictured above). Once the user clicks on each title the data in the column need to be sorted. If you implement this in a server-side scripting such as PHP, it’ll then need to send the request back to the server to get the server-side PHP script to sort the data by changing the “ORDER BY” in an SQL statement.

Continue reading ‘Sorting data made easy using JavaScript table sorter’

Ajax language translation tool based on Google Ajax Language API

I’ve built a simple Ajax language translation tool based on the Google Ajax Language API. It’s pretty easy to build one by yourself, by going through some of the examples and documentations given on the Google API page.

Continue reading ‘Ajax language translation tool based on Google Ajax Language API’

JavaScript, how to copy DIV’s or SPAN’s content to clipboard

In one of my previous posts, I had a DIV that contains some codes, and I wanted to have this code to be able to be copied by someone onto a clipboard for better viewing. So, what I had was only a very simple javascript function for doing it. And note, it works on Internet Explorer only.

Continue reading ‘JavaScript, how to copy DIV’s or SPAN’s content to clipboard’

A simple Java FTP connection + file download and upload

The Java or JDK comes with NO support of any official API for FTP connection. But there is an internal that comes in the sun.net package, but this is NOT well-documented, and you will hardly find how to use other methods within the sun.net.ftp.FtpClient class.

Continue reading ‘A simple Java FTP connection + file download and upload’