Skip to main content


Showing posts from August, 2008

Creating a Simple Countdown Timer Using JavaScript II...Using getElementById() Method

Speaking of yesterday’s post, it had the following problems: 1. It could not easily be embedded into an existing page. 2. It could not be placed wherever we wanted it to be nor it could be aligned or styled easily. 3. Rather than updating the same number to countdown it showed a series of numbers as countdown proceeded. Well all these problems can easily be solved by one of JavaScript’s powerful method getElementById() . This is documents ’s method which can be used to access HTML entities within JavaScript with the help of their IDs (which is unique). For example we can access the HTML entity and its values etc. with the ID one as: document.getElementById("one") The HTML object may be defined like below: <p id="one">some text</p> You get! OK, how can this be used to solve our problems, let’s see. As we know, the HTML entities such as <p>,<div>, <span> etc. can be placed anywhere very easily

Creating a Simple Countdown Timer Using JavaScript

Some JavaScripting today! We are going to create a simple countdown timer using JavaScript. What’s the use? Umm, I really am not creative enough to find any of its perfect use but it could be used somewhere, sometimes…and there is no harm in learning something even when there seems to be no potential use of it. Who knows maybe you’d need it sometime to add creativity to your web pages. Of course some of the techniques that we are going to use will be needed at many times, so you won’t wanna miss this! This time , let’s start off with the code first: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" > <html> <head> <title>JavaScript Countdown Timer</title> <meta http-equiv= "Content-Type" content= "text/html; charset=iso-8859-1" > <script language= "JavaScript" type= "text/JavaScript" > //to store timeout ID var tID; function tickTimer(t)

Evaluating/Executing PHP Code at Run-Time Using eval() Function

OK, so today we are going to discuss about one of the interesting functions of PHP. The eval() function. It is interesting in that it can evaluate/execute PHP code from inside scripts. This means, the eval() function can evaluate PHP code at run-time. The code itself in turn may be generated at run-time hence it could be used to execute code that may not initially be a part of the script. Let’s see some examples: eval( "echo 'hello';" ); Which is equivalent to: echo  'hello' ; One more example: <?php $n = 10 ; $code = '' ; for( $i = 0 ; $i < $n ; $i ++)      $code .= "echo $i;" ; eval( $code ); ?> Here the code to be evaluated is generated at run-time too. The code to be evaluated could be stored somewhere (like in a file or in database) and later can be retrieved and evaluated. As an example, below I’m providing the source code which would create a page that could be used to run PH

Blogger: Changing Templates without Loosing Widgets

The other day when I was trying to change the Template of this blog I faced a rather disheartening problem. Blogger said that all the Widget along with their data will be lost when changing to a third-party template. As you can see I have a link list (big one) on the sidebar, it has links to all my posts so far (>180!), man could I afford to loose that? Of course NOT! Good thing was switching to one of the templates provided by Blogger wouldn’t make me loose those widgets. Bad thing is I don’t like those templates. Those are all too old, excessively used everywhere and 2-column ones. So what did I do to save my widgets when changing to a third party Blogger template? Read along to know…(this might look like a crappy landing page that’d sell you something, believe me its NOT!) If you too are facing the same problem you can take these steps to save your widgets: STEPS: 1. Start off by going to Layout-> Edit HTML then click on Expand Widget Templ

How Do I Color-Highlight PHP Source Codes

If you’ve been a regular reader of this blog you might have wondered how I highlight PHP code using different colors. Your prompt answer would be, using some software. Well not exactly as PHP has built-in feature for highlighting source code. And of course I use that. Here are some of the different methods that you can use to highlight PHP source code, you may use any one of them depending upon what your intended purpose is. 1. If have set-up PHP as explained in Configuring Apache Web Server and PHP then you can just name your PHP files like “filename.phps” to tell PHP to highlight and show the file upon request and not execute it. You can use this method when you want to link the highlighted source from some web page. You cannot, however, embed source code into web pages using this method. 2. You can use the following function to highlight any PHP (.php) script file: highlight_file ( 'filename.php' ) ; You just have to pass the filen

Web Scraping: Gathering "Related Searches" Keyword Data From Google Search Results

You might first want to read Basic Web Scraping: Pulling Out Data From Google Search Results . In the other Basic Web Scraping post we created a Simple Web Scraper that retrieved Google’s Search Result Pages for some keyword and scraped the “Number of Pages” indexed for the keyword. That was a good starting point in learning web scraping, that’s why in this post we’re going to extend that scraper to return one more information, “Related Keywords”. Actually, Related Searches is a bunch of keywords that Google displays at the bottom of search result pages. These are not displayed all the keywords that you search for, but only for keywords that are somewhat broad. These “related Searches” are the keywords that Google has evaluated to be related with the one searched for. To scrape this, we’d first need to analyze the HTML code of Google Search Result. We need to find out where the Related Searches block is in the code, typically it’d like: <h2 clas