<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" gd:etag="W/&quot;C0AHQHs6eSp7ImA9WhRbEU0.&quot;"><id>tag:blogger.com,1999:blog-33629562</id><updated>2012-02-01T18:38:51.511+05:30</updated><category term="Personal" /><category term="Atom" /><category term="Introduction" /><category term="Sorting" /><category term="Enumeration" /><category term="Game" /><category term="Feeds" /><category term="Image" /><category term="Errors" /><category term="Arrays" /><category term="Function Overloading" /><category term="Files" /><category term="Queues" /><category term="Encryption" /><category term="2D Arrays" /><category term="Example Programs" /><category term="IDE" /><category term="Operator Overloading" /><category term="Syntax Highlighting" /><category term="Image Generation" /><category term="Strings" /><category term="Searching" /><category term="Web" /><category term="RSS" /><category term="Friend Functions" /><category term="Decryption" /><category term="Questions" /><category term="Variables" /><category term="Useful Scripts" /><category term="Software" /><category term="Questions and Answers" /><category term="XHTML" /><category term="Miscellaneous" /><category term="Apache" /><category term="Stacks" /><category term="Personel" /><category term="Inheritance" /><category term="Class" /><category term="Virtual Functions" /><category term="Structures" /><category term="WAP" /><category term="Data Structures" /><category term="CSS" /><category term="Loops" /><category term="Lightbox" /><category term="Preprocessors" /><category term="CAPTCHA" /><category term="Access Modifiers" /><category term="Pointers" /><category term="XML" /><category term="Recursion" /><category term="Problems" /><category term="Data Types" /><category term="Fancybox" /><category term="Blogger" /><category term="Algorithms" /><category term="Matrices" /><category term="Web Scraping" /><category term="Functions" /><category term="Objects" /><category term="Blogging" /><category term="PHP" /><category term="Classes" /><category term="Methods" /><category term="Linked Lists" /><category term="Random Numbers" /><category term="Programming Skills" /><category term="Polymorphism" /><category term="Mistakes" /><category term="Operators" /><category term="HTML" /><category term="Reference" /><category term="OOP" /><category term="Union" /><category term="Memory Allocation" /><category term="JavaScript" /><category term="Macros" /><category term="Merging" /><category term="Tricks" /><category term="Securing" /><category term="Complete Script" /><title>Learning Computer Programming</title><subtitle type="html">A resource for Learning Computer Programming. I post articles, tips, tricks, techniques, algorithms etc. related to C++, PHP and other programming language. Many of the things that I discuss here applies to most languages.</subtitle><link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://learning-computer-programming.blogspot.com/feeds/posts/default" /><link rel="alternate" type="text/html" href="http://learning-computer-programming.blogspot.com/" /><link rel="next" type="application/atom+xml" href="http://www.blogger.com/feeds/33629562/posts/default?start-index=26&amp;max-results=25&amp;redirect=false&amp;v=2" /><author><name>Arvind Gupta</name><uri>http://www.blogger.com/profile/17199066124402939022</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="23" height="32" src="http://one.arvind.googlepages.com/arvind_gupta_photo.jpg" /></author><generator version="7.00" uri="http://www.blogger.com">Blogger</generator><openSearch:totalResults>199</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/blogspot/TiGWE" /><feedburner:info uri="blogspot/tigwe" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry gd:etag="W/&quot;CUQEQnc-eSp7ImA9WxNbFU8.&quot;"><id>tag:blogger.com,1999:blog-33629562.post-125945877262159459</id><published>2009-11-14T15:45:00.002+05:30</published><updated>2009-11-18T11:18:23.951+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-11-18T11:18:23.951+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Web" /><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript" /><category scheme="http://www.blogger.com/atom/ns#" term="XHTML" /><category scheme="http://www.blogger.com/atom/ns#" term="Example Programs" /><category scheme="http://www.blogger.com/atom/ns#" term="Useful Scripts" /><category scheme="http://www.blogger.com/atom/ns#" term="Lightbox" /><category scheme="http://www.blogger.com/atom/ns#" term="CSS" /><category scheme="http://www.blogger.com/atom/ns#" term="Complete Script" /><category scheme="http://www.blogger.com/atom/ns#" term="HTML" /><category scheme="http://www.blogger.com/atom/ns#" term="Fancybox" /><title>Designing Your Own Lightbox in Javascript</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/qt59kMAwNa77MvM9sZAq-GHotyM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/qt59kMAwNa77MvM9sZAq-GHotyM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/qt59kMAwNa77MvM9sZAq-GHotyM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/qt59kMAwNa77MvM9sZAq-GHotyM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;In nowadays web 2.0 world use of Lightbox is very common.  While Lightbox, fancybox (similar to the former) are great scripts and have  wide uses, creating a script similar to these is never a bad idea. If you learn,  read on else use of one of those scripts, they’re great and easy-to-use.&lt;/p&gt;
&lt;p&gt;For those of you who haven’t heard about the script or don’t  know what they do, see the following image:&lt;/p&gt;
&lt;p style="text-align:center;"&gt;&lt;img src="http://www.arvindgupta.co.in/my_files/images/blackbox_scrrenshot1.png" width="500" height="242" title="Our own Lightbox in action" alt="Screenshot og Blackbox - Our own Lightbox clone" /&gt;&lt;/p&gt;
&lt;p&gt;Chances are, you might surely have seen it somewhere or the  other. These scripts are generally used to display some content in kind of like  a dialog box (modal one, for those of you who're geeks) while the rest of the content  gets blackened. Looks great? Yes it does!&lt;/p&gt;
&lt;p&gt;Okay, for those of you still here I wanna confess that I  didn’t put enough time knowing how those scripts actually work. I just got an  idea myself the other day and thought it just might work. This is not to say  that I myself have invented some new way, it’s just that I don’t know how those  scripts work but I know one way that gives similar results.&lt;/p&gt;
&lt;p&gt;As you can see from the above image, there is not much to a  simple Lightbox clone, we have a (1) Blackening effect (2) The content box.&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;Blackening Effect: For this I’ll create a &lt;code&gt;“div”&lt;/code&gt; element  on the fly and set its properties such that it has a black color and some  transparency, a large &lt;code&gt;z-index&lt;/code&gt; means floats on top of the rest of the content  and back content (with normal z-index) cannot be interacted with anymore. We’ll  fill the current screen with this &lt;code&gt;“div”&lt;/code&gt; which will require us to place this  element at the topmost and leftmost coordinates relative to the current  viewable area. This will be &lt;code&gt;(0, 0)&lt;/code&gt; when the page isn’t scrolled at all. &lt;/p&gt;
    &lt;p&gt;We’ll also have to size the element to have it span the  whole viewable area of the browser.&lt;/p&gt;
    &lt;p&gt;These two things will make sure that no matter where we have  scrolled in a page and whatever be the window size, this black overlay element always covers the current viewport.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;2. Content Box: A nicely styled box with a close button is  all we need. We’ll place it at the center of the screen. Since we have  calculated the topmost and leftmost coordinates relative to the current  viewport and we also have the current viewport’s dimension, we can easily  position this at the center, no brainer! We’ll give this a &lt;code&gt;z-index&lt;/code&gt; larger than  the black overlay element such that this is at the top of everything.&lt;/p&gt;
    &lt;p&gt;Besides this, we’ll also have to take care that these two  elements move along with the page in case user tries to scroll the page when  the our lightbox is open. This will make sure that (1) black overlay  element always fills the screen (2) content box is always at the center.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Sounds pretty simple? Well, it is! It’ll call this Blackbox,  you may call it whatever you feel like. Here is the code (&lt;a href="http://www.arvindgupta.co.in/my_files/demos/blackbox.html" rel="nofollow,noindex"&gt;Demo&lt;/a&gt; here):&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&lt;font color="#000000"&gt;
&amp;lt;!DOCTYPE html PUBLIC &lt;font color="#0000ff"&gt;&amp;quot;-//W3C//DTD XHTML 1.0 Transitional//EN&amp;quot; &amp;quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&amp;quot;&lt;/font&gt;&amp;gt;

&amp;lt;html xmlns=&lt;font color="#0000ff"&gt;&amp;quot;http://www.w3.org/1999/xhtml&amp;quot;&lt;/font&gt;&amp;gt;
&amp;lt;head&amp;gt;
&amp;lt;meta http-equiv=&lt;font color="#0000ff"&gt;&amp;quot;Content-Type&amp;quot;&lt;/font&gt; content=&lt;font color="#0000ff"&gt;&amp;quot;text/html; charset=utf-8&amp;quot;&lt;/font&gt; /&amp;gt;
&amp;lt;title&amp;gt;Blackbox - A very simple Lightbox clone&amp;lt;/title&amp;gt;

&amp;lt;script type=&lt;font color="#0000ff"&gt;&amp;quot;text/javascript&amp;quot;&lt;/font&gt;&amp;gt;
&lt;font color="#000080"&gt;&lt;i&gt;/*&lt;/i&gt;&lt;/font&gt;
&lt;font color="#000080"&gt;&lt;i&gt; * Script: Blackbox (very simple Lightbox clone)&lt;/i&gt;&lt;/font&gt;
&lt;font color="#000080"&gt;&lt;i&gt; * Author: Arvind Gupta (contact@arvindgupta.co.in)&lt;/i&gt;&lt;/font&gt;
&lt;font color="#000080"&gt;&lt;i&gt; * Date: 14-Nov-09&lt;/i&gt;&lt;/font&gt;
&lt;font color="#000080"&gt;&lt;i&gt; * Copyright: 2009 Arvind Gupta&lt;/i&gt;&lt;/font&gt;

&lt;font color="#000080"&gt;&lt;i&gt; *            You may freely use this script wherever&lt;/i&gt;&lt;/font&gt;
&lt;font color="#000080"&gt;&lt;i&gt; *         you want and in whatever way you wish&lt;/i&gt;&lt;/font&gt;
&lt;font color="#000080"&gt;&lt;i&gt; *         but please don't remove this note.&lt;/i&gt;&lt;/font&gt;
&lt;font color="#000080"&gt;&lt;i&gt; *&lt;/i&gt;&lt;/font&gt;
&lt;font color="#000080"&gt;&lt;i&gt; */&lt;/i&gt;&lt;/font&gt;

&lt;font color="#000080"&gt;&lt;i&gt;// OBJECTS&lt;/i&gt;&lt;/font&gt;

&lt;font color="#000080"&gt;&lt;i&gt;// Black overlay element&lt;/i&gt;&lt;/font&gt;
&lt;b&gt;var&lt;/b&gt; darkbox;
&lt;font color="#000080"&gt;&lt;i&gt;// Content box&lt;/i&gt;&lt;/font&gt;
&lt;b&gt;var&lt;/b&gt; content;

&lt;font color="#000080"&gt;&lt;i&gt;// FUNCTIONS&lt;/i&gt;&lt;/font&gt;
&lt;b&gt;function&lt;/b&gt; init()
{
   &lt;font color="#000080"&gt;&lt;i&gt;// Set &amp;quot;onScroll&amp;quot; event handler&lt;/i&gt;&lt;/font&gt;

   window.onscroll = scroll_box;
}

&lt;b&gt;function&lt;/b&gt; open()
{
   &lt;font color="#000080"&gt;&lt;i&gt;// Create elements&lt;/i&gt;&lt;/font&gt;
   darkbox = document.createElement(&lt;font color="#ff8000"&gt;'div'&lt;/font&gt;);
   content = document.createElement(&lt;font color="#ff8000"&gt;'div'&lt;/font&gt;);

   &lt;font color="#000080"&gt;&lt;i&gt;// Style them with the existing ids&lt;/i&gt;&lt;/font&gt;
   darkbox.id = &lt;font color="#ff8000"&gt;'darkbox'&lt;/font&gt;;
   content.id = &lt;font color="#ff8000"&gt;'content'&lt;/font&gt;;

   &lt;font color="#000080"&gt;&lt;i&gt;// FILL CONTENT BOX&lt;/i&gt;&lt;/font&gt;

   &lt;font color="#000080"&gt;&lt;i&gt;// Have the close button&lt;/i&gt;&lt;/font&gt;
   content.innerHTML = &lt;font color="#ff8000"&gt;'&amp;lt;a style=&amp;quot;position: absolute; top: -30px; right: -30px; text-decoration: none;&amp;quot; href=&amp;quot;javascript:close();&amp;quot;&amp;gt;&amp;lt;img style=&amp;quot;border: none;&amp;quot; src=&amp;quot;fancy_closebox.png&amp;quot; /&amp;gt;&amp;lt;/a&amp;gt;'&lt;/font&gt;;
   &lt;font color="#000080"&gt;&lt;i&gt;// The main content&lt;/i&gt;&lt;/font&gt;

   content.innerHTML += &lt;font color="#ff8000"&gt;'&amp;lt;div id=&amp;quot;main_content&amp;quot;&amp;gt;&amp;lt;h1&amp;gt;Hello&amp;lt;/h1&amp;gt;&amp;lt;p&amp;gt;Hello World!&amp;lt;br /&amp;gt; How is this looking?&amp;lt;/p&amp;gt;&amp;lt;/div&amp;gt;'&lt;/font&gt;;

   &lt;font color="#000080"&gt;&lt;i&gt;// Add these elements to the body&lt;/i&gt;&lt;/font&gt;

   document.body.appendChild(darkbox);
   document.body.appendChild(content);

   &lt;font color="#000080"&gt;&lt;i&gt;// Calciulate coordinates and such&lt;/i&gt;&lt;/font&gt;
   &lt;b&gt;var&lt;/b&gt; pos_top = document.documentElement.scrollTop
   &lt;b&gt;var&lt;/b&gt; pos_left = document.documentElement.scrollLeft;
   &lt;b&gt;var&lt;/b&gt; screen_width = document.documentElement.clientWidth;
   &lt;b&gt;var&lt;/b&gt; screen_height = document.documentElement.clientHeight;

   &lt;font color="#000080"&gt;&lt;i&gt;// Place the &amp;quot;darkbox&amp;quot; element and give it the size&lt;/i&gt;&lt;/font&gt;

   darkbox.style.top = pos_top + &lt;font color="#ff8000"&gt;'px'&lt;/font&gt;;
   darkbox.style.left = pos_left + &lt;font color="#ff8000"&gt;'px'&lt;/font&gt;;
   darkbox.style.height = screen_height + &lt;font color="#ff8000"&gt;'px'&lt;/font&gt;;
   darkbox.style.width = screen_width + &lt;font color="#ff8000"&gt;'px'&lt;/font&gt;;

   &lt;font color="#000080"&gt;&lt;i&gt;// Now place the content box at the center&lt;/i&gt;&lt;/font&gt;
   content.style.left = (pos_left + (screen_width / &lt;font color="#ff0080"&gt;2.0&lt;/font&gt;) - (content.offsetWidth / &lt;font color="#ff0080"&gt;2.0&lt;/font&gt;)) + &lt;font color="#ff8000"&gt;'px'&lt;/font&gt;;
   content.style.top = (pos_top + (screen_height / &lt;font color="#ff0080"&gt;2.0&lt;/font&gt;) - (content.offsetHeight / &lt;font color="#ff0080"&gt;2.0&lt;/font&gt;)) + &lt;font color="#ff8000"&gt;'px'&lt;/font&gt;;
}


&lt;b&gt;function&lt;/b&gt; scroll_box ()
{
   &lt;font color="#000080"&gt;&lt;i&gt;// If &amp;quot;Darkbox&amp;quot; open&lt;/i&gt;&lt;/font&gt;
   &lt;b&gt;if&lt;/b&gt;(darkbox != &lt;b&gt;null&lt;/b&gt;)
   {
      &lt;font color="#000080"&gt;&lt;i&gt;// Find new topmost, leftmost position w.r.t the current viewport&lt;/i&gt;&lt;/font&gt;
      &lt;font color="#000080"&gt;&lt;i&gt;// Also find new window size&lt;/i&gt;&lt;/font&gt;

      &lt;b&gt;var&lt;/b&gt; pos_top = document.documentElement.scrollTop
      &lt;b&gt;var&lt;/b&gt; pos_left = document.documentElement.scrollLeft;
      &lt;b&gt;var&lt;/b&gt; screen_width = document.documentElement.clientWidth;
      &lt;b&gt;var&lt;/b&gt; screen_height = document.documentElement.clientHeight;

      &lt;font color="#000080"&gt;&lt;i&gt;// Positions elements accordingly&lt;/i&gt;&lt;/font&gt;
      darkbox.style.top = pos_top + &lt;font color="#ff8000"&gt;'px'&lt;/font&gt;;
      darkbox.style.left = pos_left + &lt;font color="#ff8000"&gt;'px'&lt;/font&gt;;
      darkbox.style.height = screen_height + &lt;font color="#ff8000"&gt;'px'&lt;/font&gt;;
      darkbox.style.width = screen_width + &lt;font color="#ff8000"&gt;'px'&lt;/font&gt;;

      content.style.left = (pos_left + (screen_width / &lt;font color="#ff0080"&gt;2.0&lt;/font&gt;) - (content.offsetWidth / &lt;font color="#ff0080"&gt;2.0&lt;/font&gt;)) + &lt;font color="#ff8000"&gt;'px'&lt;/font&gt;;
      content.style.top = (pos_top + (screen_height / &lt;font color="#ff0080"&gt;2.0&lt;/font&gt;) - (content.offsetHeight / &lt;font color="#ff0080"&gt;2.0&lt;/font&gt;)) + &lt;font color="#ff8000"&gt;'px'&lt;/font&gt;;
   }
}


&lt;b&gt;function&lt;/b&gt; close()
{
   &lt;font color="#000080"&gt;&lt;i&gt;// Delete elements&lt;/i&gt;&lt;/font&gt;
   document.body.removeChild(darkbox);
   document.body.removeChild(content);
}
&amp;lt;/script&amp;gt;

&amp;lt;style&amp;gt;
#darkbox {
   position: absolute;
   top: &lt;font color="#ff0080"&gt;0px&lt;/font&gt;;
   left: &lt;font color="#ff0080"&gt;0px&lt;/font&gt;;
   opacity: &lt;font color="#ff0080"&gt;0.6&lt;/font&gt;;
   filter:alpha(opacity=&lt;font color="#ff0080"&gt;60&lt;/font&gt;);
   background: #000;
}

#content {
   position: absolute;
   z-index: &lt;font color="#ff0080"&gt;1001&lt;/font&gt;;
   background: #fff;
   border: &lt;font color="#ff0080"&gt;10px&lt;/font&gt; solid #000;
   width: &lt;font color="#ff0080"&gt;500px&lt;/font&gt;;
   height: &lt;font color="#ff0080"&gt;300px&lt;/font&gt;;
}
#content #main_content {
   overflow: auto;
   width: &lt;font color="#ff0080"&gt;500px&lt;/font&gt;;
   height: &lt;font color="#ff0080"&gt;300px&lt;/font&gt;;
}

&amp;lt;/style&amp;gt;
&amp;lt;/head&amp;gt;

&amp;lt;body onload=&lt;font color="#0000ff"&gt;&amp;quot;init();&amp;quot;&lt;/font&gt;&amp;gt;
&amp;lt;a href=&lt;font color="#0000ff"&gt;&amp;quot;javascript:open()&amp;quot;&lt;/font&gt;&amp;gt;Open Box&amp;lt;/a&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&lt;/font&gt;&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Related Posts:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2009/09/simple-pong-game-using-javascript.html"&gt;A Simple Pong Game using JavaScript&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2009/09/moving-positioning-image-using.html"&gt;Moving (Positioning) an Image Using JavaScript&lt;/a&gt; &lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/08/creating-simple-countdown-timer-using_14.html"&gt;Creating a Simple Countdown Timer Using JavaScript II...Using getElementById() Method&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/08/creating-simple-countdown-timer-using.html"&gt;Creating a Simple Countdown Timer Using JavaScript&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/06/creating-simple-html-form-validation.html"&gt;Creating a Simple HTML Form Validation System Using JavaScript&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/33629562-125945877262159459?l=learning-computer-programming.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TiGWE/~4/sLgj7ilQToE" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://learning-computer-programming.blogspot.com/feeds/125945877262159459/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://learning-computer-programming.blogspot.com/2009/11/designing-your-own-lightbox-in.html#comment-form" title="17 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/33629562/posts/default/125945877262159459?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/33629562/posts/default/125945877262159459?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/TiGWE/~3/sLgj7ilQToE/designing-your-own-lightbox-in.html" title="Designing Your Own Lightbox in Javascript" /><author><name>Arvind Gupta</name><uri>http://www.blogger.com/profile/17199066124402939022</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="23" height="32" src="http://one.arvind.googlepages.com/arvind_gupta_photo.jpg" /></author><thr:total>17</thr:total><feedburner:origLink>http://learning-computer-programming.blogspot.com/2009/11/designing-your-own-lightbox-in.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkMEQXo9fCp7ImA9WxNWF0w.&quot;"><id>tag:blogger.com,1999:blog-33629562.post-3315070541697757602</id><published>2009-10-17T00:10:00.001+05:30</published><updated>2009-10-17T00:10:00.464+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-10-17T00:10:00.464+05:30</app:edited><title>Happy Diwali</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/3tM84viiPyM2j-68Rq-cGwJ-KSY/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/3tM84viiPyM2j-68Rq-cGwJ-KSY/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/3tM84viiPyM2j-68Rq-cGwJ-KSY/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/3tM84viiPyM2j-68Rq-cGwJ-KSY/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div align="center"&gt;
&lt;img src="http://www.arvindgupta.co.in/my_files/images/happy_diwali01.jpg" title="Happy Diwali" alt="Wishing you a safe and happy Diwali" /&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/33629562-3315070541697757602?l=learning-computer-programming.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TiGWE/~4/gbzt6LeoDzQ" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://learning-computer-programming.blogspot.com/feeds/3315070541697757602/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://learning-computer-programming.blogspot.com/2009/10/happy-diwali.html#comment-form" title="5 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/33629562/posts/default/3315070541697757602?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/33629562/posts/default/3315070541697757602?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/TiGWE/~3/gbzt6LeoDzQ/happy-diwali.html" title="Happy Diwali" /><author><name>Arvind Gupta</name><uri>http://www.blogger.com/profile/17199066124402939022</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="23" height="32" src="http://one.arvind.googlepages.com/arvind_gupta_photo.jpg" /></author><thr:total>5</thr:total><feedburner:origLink>http://learning-computer-programming.blogspot.com/2009/10/happy-diwali.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUAHQH08eyp7ImA9WxFaGUk.&quot;"><id>tag:blogger.com,1999:blog-33629562.post-1583020333460339742</id><published>2009-09-15T12:51:00.005+05:30</published><updated>2010-07-24T10:32:11.373+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-07-24T10:32:11.373+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript" /><category scheme="http://www.blogger.com/atom/ns#" term="Game" /><category scheme="http://www.blogger.com/atom/ns#" term="XHTML" /><category scheme="http://www.blogger.com/atom/ns#" term="Example Programs" /><category scheme="http://www.blogger.com/atom/ns#" term="Image" /><category scheme="http://www.blogger.com/atom/ns#" term="HTML" /><title>A Simple Pong Game using JavaScript</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/7rRqbPlREDfwr1qwUgD6H9P5OOk/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/7rRqbPlREDfwr1qwUgD6H9P5OOk/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/7rRqbPlREDfwr1qwUgD6H9P5OOk/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/7rRqbPlREDfwr1qwUgD6H9P5OOk/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p align="center"&gt;&lt;img src="pong_scrnsht.png" width="250" height="197" alt="Pong Game in JavaScript Screenshot" title="Pong Game Example in JavaScript" /&gt;&lt;/p&gt;
&lt;p&gt;Having the knowledge of moving images using JavaScript,  we’ll be creating a small Ping Pong game as an example for this post.&lt;/p&gt;
&lt;p&gt;Today we’ll learn to do a few new things in JavaScript:&lt;/p&gt;
&lt;p&gt;1. Executing some code every specified time interval (for  game loop).&lt;br /&gt;
  2. Tracking and using mouse movements.&lt;br /&gt;
  3. Attaching code (function) to events.&lt;/p&gt;
&lt;h2&gt;Game Theory&lt;/h2&gt;
&lt;p&gt;As you should be knowing, in this game there is one ball and  two paddles at two ends. One is user-controlled the other, for this example, is  CPU controlled. User has to move the paddle in order not to let the ball pass  through, CPU also has to do the same thing. Whoever’s side the ball passes  through looses the game.&lt;/p&gt;
&lt;p&gt;There are a few objects which can interact with each other,  these are ball, paddles, walls. Let’s see the various interactions that can  take place between these:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;Ball Hitting Upper/Lower Wall – Ball will bounce off.&lt;br /&gt;
    &lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Ball Passing Through Either Side – Player or CPU,  depending on whose side ball passed through, will loose the game.&lt;br /&gt;
    &lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Ball Hitting Paddle  – It’ll bounce off&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;We’ll need to take care of these events:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;Page Load – Game objects will be initialized&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Game Start – Mouse click on the player paddle will start  the game.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Mouse Movements – Inside the game area (a div), the  paddle will follow the y-position of the mouse. Paddle however should not get  past the boundaries.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;CPU Paddle – The paddle will follow the ball by moving  up/down depending the relative position of the ball. We’ve added a little intelligence  by only moving the paddle while ball is coming towards it. This will make the  movement as well as the game look more real.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;Code&lt;/h2&gt;
&lt;p&gt;NOTE: Put two files &lt;a href="http://www.arvindgupta.co.in/my_files/images/ball_small.png"&gt;ball_small.png&lt;/a&gt;, &lt;a href="http://www.arvindgupta.co.in/my_files/images/paddle.PNG"&gt;paddle.png&lt;/a&gt; (Right-Click &amp;quot;Save As&amp;quot;)  in the same directory the script is in.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&lt;font color="#000000"&gt;
&amp;lt;!DOCTYPE html PUBLIC &lt;font color="#0000ff"&gt;&amp;quot;-//W3C//DTD XHTML 1.0 Transitional//EN&amp;quot; &amp;quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&amp;quot;&lt;/font&gt;&amp;gt;

&amp;lt;html xmlns=&lt;font color="#0000ff"&gt;&amp;quot;http://www.w3.org/1999/xhtml&amp;quot;&lt;/font&gt;&amp;gt;
&amp;lt;head&amp;gt;
&amp;lt;meta http-equiv=&lt;font color="#0000ff"&gt;&amp;quot;Content-Type&amp;quot;&lt;/font&gt; content=&lt;font color="#0000ff"&gt;&amp;quot;text/html; charset=utf-8&amp;quot;&lt;/font&gt; /&amp;gt;
&amp;lt;title&amp;gt;Pong Game In JavaScript&amp;lt;/title&amp;gt;

&amp;lt;style&amp;gt;
#box
{
   width: &lt;font color="#ff0080"&gt;500px&lt;/font&gt;;
   height: &lt;font color="#ff0080"&gt;300px&lt;/font&gt;;
   margin: auto;
   border: &lt;font color="#ff0080"&gt;5px&lt;/font&gt; solid #ccc;
   position: relative;
   overflow: hidden;
}

.ob
{
   position: absolute;
   border: &lt;font color="#ff0080"&gt;0px&lt;/font&gt;;
}
&amp;lt;/style&amp;gt;
&amp;lt;script type=&lt;font color="#0000ff"&gt;&amp;quot;application/javascript&amp;quot;&lt;/font&gt;&amp;gt;

&lt;font color="#000080"&gt;&lt;i&gt;// CHANGE THESE, IF REQUIRED&lt;/i&gt;&lt;/font&gt;
&lt;b&gt;var&lt;/b&gt; Speed = &lt;font color="#ff0080"&gt;5&lt;/font&gt;; &lt;font color="#000080"&gt;&lt;i&gt;// Speed of ball (pixels/step)&lt;/i&gt;&lt;/font&gt;
&lt;b&gt;var&lt;/b&gt; CPUSpeed = &lt;font color="#ff0080"&gt;5&lt;/font&gt;; &lt;font color="#000080"&gt;&lt;i&gt;// Speed of CPU Paddle (pixels/step)&lt;/i&gt;&lt;/font&gt;

&lt;font color="#000080"&gt;&lt;i&gt;// Short references to objects&lt;/i&gt;&lt;/font&gt;
&lt;b&gt;var&lt;/b&gt; paddle1;
&lt;b&gt;var&lt;/b&gt; paddle2;
&lt;b&gt;var&lt;/b&gt; ball;
&lt;b&gt;var&lt;/b&gt; box;
&lt;b&gt;var&lt;/b&gt; msg;


&lt;font color="#000080"&gt;&lt;i&gt;// For internal use&lt;/i&gt;&lt;/font&gt;
&lt;b&gt;var&lt;/b&gt; dx, dy; &lt;font color="#000080"&gt;&lt;i&gt;// Speed in x and y directions&lt;/i&gt;&lt;/font&gt;
&lt;b&gt;var&lt;/b&gt; ballX, ballY; &lt;font color="#000080"&gt;&lt;i&gt;// x and y positions of ball&lt;/i&gt;&lt;/font&gt;
&lt;b&gt;var&lt;/b&gt; playerY; &lt;font color="#000080"&gt;&lt;i&gt;// y position of player paddle (x fixed)&lt;/i&gt;&lt;/font&gt;

&lt;b&gt;var&lt;/b&gt; cpuY; &lt;font color="#000080"&gt;&lt;i&gt;// y position of CPU paddle (x fixed)&lt;/i&gt;&lt;/font&gt;
&lt;b&gt;var&lt;/b&gt; iID; &lt;font color="#000080"&gt;&lt;i&gt;// To store ID of set interval used to clear it when required&lt;/i&gt;&lt;/font&gt;

&lt;font color="#000080"&gt;&lt;i&gt;// Attach a function to onLoad event&lt;/i&gt;&lt;/font&gt;
window.onload = Init;

&lt;font color="#000080"&gt;&lt;i&gt;// INITIALIZE GAME OBJECTS&lt;/i&gt;&lt;/font&gt;
&lt;b&gt;function&lt;/b&gt; Init()
{
   &lt;font color="#000080"&gt;&lt;i&gt;// Make short refrences to objects&lt;/i&gt;&lt;/font&gt;

   paddle1 = document.getElementById(&lt;font color="#ff8000"&gt;'paddle1'&lt;/font&gt;);
   paddle2 = document.getElementById(&lt;font color="#ff8000"&gt;'paddle2'&lt;/font&gt;);
   ball = document.getElementById(&lt;font color="#ff8000"&gt;'ball'&lt;/font&gt;);
   box = document.getElementById(&lt;font color="#ff8000"&gt;'box'&lt;/font&gt;);
   msg = document.getElementById(&lt;font color="#ff8000"&gt;'msg'&lt;/font&gt;);

   &lt;font color="#000080"&gt;&lt;i&gt;// Initial values&lt;/i&gt;&lt;/font&gt;
   ballX = (box.offsetWidth / &lt;font color="#ff0080"&gt;2&lt;/font&gt;) - (ball.offsetWidth / &lt;font color="#ff0080"&gt;2&lt;/font&gt;);
   ballY = (box.offsetHeight / &lt;font color="#ff0080"&gt;2&lt;/font&gt;) - (ball.offsetHeight / &lt;font color="#ff0080"&gt;2&lt;/font&gt;);
   cpuY = (box.offsetHeight / &lt;font color="#ff0080"&gt;2&lt;/font&gt;) - (paddle2.offsetHeight / &lt;font color="#ff0080"&gt;2&lt;/font&gt;);
   playerY = (box.offsetHeight / &lt;font color="#ff0080"&gt;2&lt;/font&gt;) - (paddle1.offsetHeight / &lt;font color="#ff0080"&gt;2&lt;/font&gt;);
   dx = dy = Speed;

   paddle1.style.left = &lt;font color="#ff0080"&gt;20&lt;/font&gt; + &lt;font color="#ff8000"&gt;'px'&lt;/font&gt;;
   paddle1.style.top = playerY + &lt;font color="#ff8000"&gt;'px'&lt;/font&gt;;
   paddle2.style.left = box.offsetWidth - (&lt;font color="#ff0080"&gt;20&lt;/font&gt; + paddle2.offsetWidth) + &lt;font color="#ff8000"&gt;'px'&lt;/font&gt;;
   paddle2.style.top = cpuY + &lt;font color="#ff8000"&gt;'px'&lt;/font&gt;;
   ball.style.left = ballX + &lt;font color="#ff8000"&gt;'px'&lt;/font&gt;;
   ball.style.top = ballY + &lt;font color="#ff8000"&gt;'px'&lt;/font&gt;;

   &lt;font color="#000080"&gt;&lt;i&gt;// Show message&lt;/i&gt;&lt;/font&gt;

   msg.innerHTML = &lt;font color="#ff8000"&gt;'&amp;lt;h2&amp;gt;Click on Paddle to Start Game.&amp;lt;/h2&amp;gt;'&lt;/font&gt;;
}

&lt;font color="#000080"&gt;&lt;i&gt;// START GAME&lt;/i&gt;&lt;/font&gt;
&lt;b&gt;function&lt;/b&gt; Start()
{
   &lt;font color="#000080"&gt;&lt;i&gt;// Attach a function to onmousemove event of the box&lt;/i&gt;&lt;/font&gt;
   box.onmousemove = MovePaddle;
   &lt;font color="#000080"&gt;&lt;i&gt;// Call 'GameLoop()' function every 10 milliseconds&lt;/i&gt;&lt;/font&gt;

   iID = setInterval(&lt;font color="#ff8000"&gt;'GameLoop()'&lt;/font&gt;, &lt;font color="#ff0080"&gt;10&lt;/font&gt;);

   msg.innerHTML = &lt;font color="#ff8000"&gt;''&lt;/font&gt;;
}

&lt;font color="#000080"&gt;&lt;i&gt;// MAIN GAME LOOP, CALLED REPEATEDLY&lt;/i&gt;&lt;/font&gt;
&lt;b&gt;function&lt;/b&gt; GameLoop()
{
   &lt;font color="#000080"&gt;&lt;i&gt;// MOVE BALL&lt;/i&gt;&lt;/font&gt;
   ballX += dx;
   ballY += dy;

   &lt;font color="#000080"&gt;&lt;i&gt;// See if ball is past player paddle&lt;/i&gt;&lt;/font&gt;

   &lt;b&gt;if&lt;/b&gt;(ballX &amp;lt; &lt;font color="#ff0080"&gt;0&lt;/font&gt;)
   {
      clearInterval(iID);
      Init();

      box.onmousemove = &lt;font color="#ff8000"&gt;''&lt;/font&gt;;

      msg.innerHTML = &lt;font color="#ff8000"&gt;'&amp;lt;h2&amp;gt;You Loose!&amp;lt;br/&amp;gt;Click on Paddle to Re-Start Game.&amp;lt;/h2&amp;gt;'&lt;/font&gt;;
   }

   &lt;font color="#000080"&gt;&lt;i&gt;// See if ball is past CPU paddle&lt;/i&gt;&lt;/font&gt;

   &lt;b&gt;if&lt;/b&gt;((ballX + ball.offsetWidth) &amp;gt; box.offsetWidth)
   {
      clearInterval(iID);
      Init();

      box.onmousemove = &lt;font color="#ff8000"&gt;''&lt;/font&gt;;

      msg.innerHTML = &lt;font color="#ff8000"&gt;'&amp;lt;h2&amp;gt;You Win!&amp;lt;br/&amp;gt;Click on Paddle to Re-Start Game.&amp;lt;/h2&amp;gt;'&lt;/font&gt;;
   }

   &lt;font color="#000080"&gt;&lt;i&gt;// COLLISION DETECTION&lt;/i&gt;&lt;/font&gt;

   &lt;font color="#000080"&gt;&lt;i&gt;// If ball hits upper or lower wall&lt;/i&gt;&lt;/font&gt;
   &lt;b&gt;if&lt;/b&gt;(ballY &amp;lt; &lt;font color="#ff0080"&gt;0&lt;/font&gt; || ((ballY + ball.offsetHeight) &amp;gt; box.offsetHeight))
      dy = -dy; &lt;font color="#000080"&gt;&lt;i&gt;// Make x direction opposite&lt;/i&gt;&lt;/font&gt;

   &lt;font color="#000080"&gt;&lt;i&gt;// If ball hits player paddle&lt;/i&gt;&lt;/font&gt;

   &lt;b&gt;if&lt;/b&gt;(ballX &amp;lt; (paddle1.offsetLeft + paddle1.offsetWidth))
      &lt;b&gt;if&lt;/b&gt;(((ballY + ball.offsetHeight) &amp;gt; playerY) &amp;amp;&amp;amp; ballY &amp;lt; (playerY + paddle1.offsetHeight))
         dx = -dx;

   &lt;font color="#000080"&gt;&lt;i&gt;// If ball hits CPU paddle&lt;/i&gt;&lt;/font&gt;
   &lt;b&gt;if&lt;/b&gt;((ballX + ball.offsetWidth) &amp;gt; paddle2.offsetLeft)
      &lt;b&gt;if&lt;/b&gt;(((ballY + ball.offsetHeight) &amp;gt; cpuY) &amp;amp;&amp;amp; ballY &amp;lt; (cpuY + paddle2.offsetHeight))
         dx = -dx;

   &lt;font color="#000080"&gt;&lt;i&gt;// Place ball at calculated positions&lt;/i&gt;&lt;/font&gt;

   ball.style.left = ballX + &lt;font color="#ff8000"&gt;'px'&lt;/font&gt;;
   ball.style.top = ballY + &lt;font color="#ff8000"&gt;'px'&lt;/font&gt;;

   &lt;font color="#000080"&gt;&lt;i&gt;// MOVE CPU PADDLE&lt;/i&gt;&lt;/font&gt;
   &lt;font color="#000080"&gt;&lt;i&gt;// Move paddle only if ball is coming towards the CPU paddle&lt;/i&gt;&lt;/font&gt;
   &lt;b&gt;if&lt;/b&gt;(dx &amp;gt; &lt;font color="#ff0080"&gt;0&lt;/font&gt;)
   {
      &lt;b&gt;if&lt;/b&gt;((cpuY + (paddle2.offsetHeight / &lt;font color="#ff0080"&gt;2&lt;/font&gt;)) &amp;gt; (ballY + ball.offsetHeight)) cpuY -= CPUSpeed;
      &lt;b&gt;else&lt;/b&gt; cpuY += CPUSpeed;

      paddle2.style.top = cpuY + &lt;font color="#ff8000"&gt;'px'&lt;/font&gt;;
   }
}


&lt;font color="#000080"&gt;&lt;i&gt;// TO MOVE PLAYER PADDLE ON MOUSE MOVE EVENT&lt;/i&gt;&lt;/font&gt;
&lt;b&gt;function&lt;/b&gt; MovePaddle(e)
{
   &lt;font color="#000080"&gt;&lt;i&gt;// Fetch y coordinate of mouse&lt;/i&gt;&lt;/font&gt;
   &lt;b&gt;var&lt;/b&gt; y = (e.clientY - (box.offsetTop - document.documentElement.scrollTop));
   &lt;font color="#000080"&gt;&lt;i&gt;// Here, (box.offsetTop - document.documentElement.scrollTop) will get the relative&lt;/i&gt;&lt;/font&gt;
   &lt;font color="#000080"&gt;&lt;i&gt;// position of &amp;quot;box&amp;quot; w.r.t to current scroll postion&lt;/i&gt;&lt;/font&gt;

   &lt;font color="#000080"&gt;&lt;i&gt;// If y below lower boundary (cannot go above upper boundary - &lt;/i&gt;&lt;/font&gt;
   &lt;font color="#000080"&gt;&lt;i&gt;// mousemove event only generated when mouse is inside box&lt;/i&gt;&lt;/font&gt;
   &lt;b&gt;if&lt;/b&gt;(y &amp;gt; (box.offsetHeight - paddle1.offsetHeight))
      y = (box.offsetHeight - paddle1.offsetHeight);

   &lt;font color="#000080"&gt;&lt;i&gt;// Copy position&lt;/i&gt;&lt;/font&gt;
   playerY = y;
   &lt;font color="#000080"&gt;&lt;i&gt;// Set position&lt;/i&gt;&lt;/font&gt;

   paddle1.style.top = y + &lt;font color="#ff8000"&gt;'px'&lt;/font&gt;;
}
&amp;lt;/script&amp;gt;
&amp;lt;/head&amp;gt;

&amp;lt;body bgcolor=&lt;font color="#0000ff"&gt;&amp;quot;#fff&amp;quot;&lt;/font&gt;&amp;gt;
&amp;lt;h1 align=&lt;font color="#0000ff"&gt;&amp;quot;center&amp;quot;&lt;/font&gt;&amp;gt;Pong Game Example &lt;b&gt;in&lt;/b&gt; JavaScript&amp;lt;/h1&amp;gt;

&amp;lt;div id=&lt;font color="#0000ff"&gt;&amp;quot;box&amp;quot;&lt;/font&gt;&amp;gt;
&amp;lt;img &lt;b&gt;class&lt;/b&gt;=&lt;font color="#0000ff"&gt;&amp;quot;ob&amp;quot;&lt;/font&gt; id=&lt;font color="#0000ff"&gt;&amp;quot;paddle1&amp;quot;&lt;/font&gt; src=&lt;font color="#0000ff"&gt;&amp;quot;paddle.PNG&amp;quot;&lt;/font&gt; onclick=&lt;font color="#0000ff"&gt;&amp;quot;javascript: Start()&amp;quot;&lt;/font&gt;/&amp;gt;

&amp;lt;img &lt;b&gt;class&lt;/b&gt;=&lt;font color="#0000ff"&gt;&amp;quot;ob&amp;quot;&lt;/font&gt; id=&lt;font color="#0000ff"&gt;&amp;quot;paddle2&amp;quot;&lt;/font&gt; src=&lt;font color="#0000ff"&gt;&amp;quot;paddle.PNG&amp;quot;&lt;/font&gt; /&amp;gt;
&amp;lt;img &lt;b&gt;class&lt;/b&gt;=&lt;font color="#0000ff"&gt;&amp;quot;ob&amp;quot;&lt;/font&gt; id=&lt;font color="#0000ff"&gt;&amp;quot;ball&amp;quot;&lt;/font&gt; src=&lt;font color="#0000ff"&gt;&amp;quot;ball_small.PNG&amp;quot;&lt;/font&gt; /&amp;gt;

&amp;lt;/div&amp;gt;
&amp;lt;div id=&lt;font color="#0000ff"&gt;&amp;quot;msg&amp;quot;&lt;/font&gt; align=&lt;font color="#0000ff"&gt;&amp;quot;center&amp;quot;&lt;/font&gt;&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&lt;/font&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Related Posts:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2009/09/moving-positioning-image-using.html"&gt;Moving (Positioning) an Image Using JavaScript&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/08/creating-simple-countdown-timer-using_14.html"&gt;Creating a Simple Countdown Timer Using JavaScript II...Using getElementById() Method&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/08/creating-simple-countdown-timer-using.html"&gt;Creating a Simple Countdown Timer Using JavaScript&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/06/creating-simple-html-form-validation.html"&gt;Creating a Simple HTML Form Validation System Using JavaScript&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/33629562-1583020333460339742?l=learning-computer-programming.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TiGWE/~4/HziNmOMALFw" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://learning-computer-programming.blogspot.com/feeds/1583020333460339742/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://learning-computer-programming.blogspot.com/2009/09/simple-pong-game-using-javascript.html#comment-form" title="9 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/33629562/posts/default/1583020333460339742?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/33629562/posts/default/1583020333460339742?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/TiGWE/~3/HziNmOMALFw/simple-pong-game-using-javascript.html" title="A Simple Pong Game using JavaScript" /><author><name>Arvind Gupta</name><uri>http://www.blogger.com/profile/17199066124402939022</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="23" height="32" src="http://one.arvind.googlepages.com/arvind_gupta_photo.jpg" /></author><thr:total>9</thr:total><feedburner:origLink>http://learning-computer-programming.blogspot.com/2009/09/simple-pong-game-using-javascript.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEMBR30-eSp7ImA9WxNRFUo.&quot;"><id>tag:blogger.com,1999:blog-33629562.post-4848397658779681995</id><published>2009-09-06T11:17:00.002+05:30</published><updated>2009-09-10T15:24:16.351+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-09-10T15:24:16.351+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript" /><category scheme="http://www.blogger.com/atom/ns#" term="XHTML" /><category scheme="http://www.blogger.com/atom/ns#" term="Example Programs" /><category scheme="http://www.blogger.com/atom/ns#" term="Image" /><category scheme="http://www.blogger.com/atom/ns#" term="HTML" /><title>Moving (Positioning) an Image Using JavaScript</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/BiBmSthAINK3MS34e--RSs5mh5A/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/BiBmSthAINK3MS34e--RSs5mh5A/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/BiBmSthAINK3MS34e--RSs5mh5A/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/BiBmSthAINK3MS34e--RSs5mh5A/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p align="center"&gt;&lt;img src="http://www.arvindgupta.co.in/my_files/images/move_by_buttons.png" title="Moving (Positioning) an Image Using JavaScript Example" width="250" height="161" alt="Screenshot" /&gt;&lt;/p&gt;
&lt;p&gt;In this post we’re going to learn how we can move an image  around using JavaScript. We’ll have four control links (Left, Right, Up, Down)  that’ll move the image.&lt;/p&gt;
&lt;p&gt;Reading along  you’ll learn:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;What the &lt;code&gt;absolute&lt;/code&gt; and &lt;code&gt;relative&lt;/code&gt; positions do&lt;/li&gt;
  &lt;li&gt;How some JavaScript function can be invoked automatically  on page load&lt;/li&gt;
  &lt;li&gt;How JavaScript can be used to manipulate the “style”  properties of elements&lt;/li&gt;
  &lt;li&gt;How JavaScript can be used to change these properties&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Okay, now let’s start!&lt;/p&gt;
&lt;h3&gt;THEORY&lt;/h3&gt;
&lt;p&gt;We’re going to have the following elements in the page:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;A container (&lt;code&gt;div&lt;/code&gt;)&lt;/li&gt;
  &lt;li&gt;An image&lt;/li&gt;
  &lt;li&gt;Control links&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;Container&lt;/h3&gt;
&lt;p&gt;The container would be styled to have a size of 500px by  300px. It’d have &lt;code&gt;position: relative&lt;/code&gt; which makes anything inside to be  positioned with respect to this container. It’s done to make the image move  independent of the placement of the container. We’ll also make the overflows  from the container to be “&lt;code&gt;hidden&lt;/code&gt;”.&lt;/p&gt;
&lt;h3&gt;Image&lt;/h3&gt;
&lt;p&gt;The image would be given &lt;code&gt;position: absolute&lt;/code&gt; which means it  can be positioned with absolute (left (x), top (y)) values. Normally images  (like other elements) are positioned, aligned, wrapped accordingly with other  elements. The absolute position however, gives us the power to place the image  (or other element) freely.&lt;/p&gt;
&lt;h3&gt;Control Links&lt;/h3&gt;
&lt;p&gt;Control Links  will be  used to invoke the functions to move the image in the respective directions.&lt;/p&gt;
&lt;h3&gt;Misc.&lt;/h3&gt;
&lt;p&gt;The functions being called by the Control links will  manipulate the position of the image using one &lt;code&gt;document.getElementbyId()&lt;/code&gt;  function.&lt;/p&gt;
&lt;p&gt;This function is used to reference elements in the document  uniquely by using their IDs (which are supposed to be unique for each element).  The style properties of elements are referenced as:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;document.getElementById(&amp;lt;ID&amp;gt;).style.&amp;lt;STYLE-NAME&amp;gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;We’ll be using the &lt;code&gt;onload &lt;/code&gt;event of the body element to  invoke the &lt;code&gt;Init()&lt;/code&gt; function initially on page load.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&lt;font color="#800080"&gt;&amp;lt;body &lt;strong&gt;onload=&lt;font color="#0000ff"&gt;&amp;quot;javascript:Init()&amp;quot;&lt;/font&gt;&lt;/strong&gt;&amp;gt;&lt;/font&gt;&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;WORKING&lt;/h3&gt;
&lt;p&gt;When the page loads, the function &lt;code&gt;Init()&lt;/code&gt; is getting called  which sets the initial position of the image.&lt;/p&gt;
&lt;p&gt;When a control link is clicked, the respective coordinate (x  or y) is modified and the new value is set in the following line:&lt;/p&gt;
&lt;code&gt;
&lt;p&gt;document.getElementById('img1').style.left = x + 'px';&lt;/p&gt;
&lt;p&gt;document.getElementById('img1').style.top = y + 'px';&lt;/p&gt;
&lt;/code&gt;
&lt;h3&gt;CODE&lt;/h3&gt;

&lt;pre&gt;&lt;code&gt;&lt;font color="#000000"&gt;&amp;lt;!DOCTYPE html PUBLIC &lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;quot;-//W3C//DTD XHTML 1.0 Transitional//EN&amp;quot; &amp;quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&amp;quot;&lt;/font&gt;&amp;gt;
&lt;font color="#800080"&gt;&lt;b&gt;&amp;lt;html&lt;/b&gt;&lt;/font&gt; &lt;b&gt;xmlns&lt;/b&gt;=&lt;font color="#0000ff"&gt;&amp;quot;http://www.w3.org/1999/xhtml&amp;quot;&lt;/font&gt;&amp;gt;
&lt;font color="#800080"&gt;&lt;b&gt;&amp;lt;head&lt;/b&gt;&lt;/font&gt;&amp;gt;
&lt;font color="#800080"&gt;&lt;b&gt;&amp;lt;meta&lt;/b&gt;&lt;/font&gt; &lt;b&gt;http&lt;/b&gt;-&lt;b&gt;equiv&lt;/b&gt;=&lt;font color="#0000ff"&gt;&amp;quot;Content-Type&amp;quot;&lt;/font&gt; &lt;b&gt;content&lt;/b&gt;=&lt;font color="#0000ff"&gt;&amp;quot;text/html; charset=utf-8&amp;quot;&lt;/font&gt; /&amp;gt;
&lt;font color="#800080"&gt;&lt;b&gt;&amp;lt;title&lt;/b&gt;&lt;/font&gt;&amp;gt;JavaScript: Moving an Image&lt;font color="#800080"&gt;&lt;b&gt;&amp;lt;/title&lt;/b&gt;&lt;/font&gt;&amp;gt;&lt;font color="#000000"&gt;
&amp;lt;script type=&lt;font color="#0000ff"&gt;&amp;quot;application/ecmascript&amp;quot;&lt;/font&gt;&amp;gt;

&lt;font color="#009900"&gt;// --CHANGE THESE IF REQUIRED--&lt;/font&gt;
&lt;font color="#009900"&gt;// Initial x-position of image&lt;/font&gt;
&lt;b&gt;var&lt;/b&gt; x = &lt;font color="#ff0080"&gt;200&lt;/font&gt;;
&lt;font color="#009900"&gt;// Initial y-position of image&lt;/font&gt;
&lt;b&gt;var&lt;/b&gt; y =&lt;font color="#ff0080"&gt;100&lt;/font&gt;;
&lt;font color="#009900"&gt;// Pixels to move in each step&lt;/font&gt;
&lt;b&gt;var&lt;/b&gt; inc = &lt;font color="#ff0080"&gt;10&lt;/font&gt;;

&lt;b&gt;function&lt;/b&gt; Init()
{
   document.getElementById(&lt;font color="#ff8000"&gt;'img1'&lt;/font&gt;).style.left = x + &lt;font color="#ff8000"&gt;'px'&lt;/font&gt;;
   document.getElementById(&lt;font color="#ff8000"&gt;'img1'&lt;/font&gt;).style.top = y + &lt;font color="#ff8000"&gt;'px'&lt;/font&gt;;
}
&lt;b&gt;function&lt;/b&gt; moveRight()
{
   x += inc;

   document.getElementById(&lt;font color="#ff8000"&gt;'img1'&lt;/font&gt;).style.left = x + &lt;font color="#ff8000"&gt;'px'&lt;/font&gt;;
}

&lt;b&gt;function&lt;/b&gt; moveLeft()
{
   x -= inc;

   document.getElementById(&lt;font color="#ff8000"&gt;'img1'&lt;/font&gt;).style.left = x + &lt;font color="#ff8000"&gt;'px'&lt;/font&gt;;
}

&lt;b&gt;function&lt;/b&gt; moveUp()
{
   y -= inc;

   document.getElementById(&lt;font color="#ff8000"&gt;'img1'&lt;/font&gt;).style.top = y + &lt;font color="#ff8000"&gt;'px'&lt;/font&gt;;
}

&lt;b&gt;function&lt;/b&gt; moveDown()
{
   y += inc;

   document.getElementById(&lt;font color="#ff8000"&gt;'img1'&lt;/font&gt;).style.top = y + &lt;font color="#ff8000"&gt;'px'&lt;/font&gt;;
}
&amp;lt;/script&amp;gt;
&lt;/font&gt;
&lt;font color="#800080"&gt;
&lt;b&gt;&amp;lt;style&lt;/b&gt;&amp;gt;
#box
{
   width: &lt;font color="#ff0080"&gt;500px&lt;/font&gt;;
   height: &lt;font color="#ff0080"&gt;300px&lt;/font&gt;;
   position: relative;
   margin: &lt;font color="#ff0080"&gt;20px&lt;/font&gt; auto &lt;font color="#ff0080"&gt;0px&lt;/font&gt; auto;
   border: &lt;font color="#ff0080"&gt;5px&lt;/font&gt; outset #000;
   overflow: hidden;
}

.image
{
   position: absolute;
   z-index: &lt;font color="#ff0080"&gt;100&lt;/font&gt;;
}
&lt;b&gt;&amp;lt;/style&lt;/b&gt;&amp;gt;
&lt;b&gt;&amp;lt;/head&lt;/b&gt;&amp;gt;

&lt;b&gt;&amp;lt;body&lt;/b&gt; &lt;b&gt;onload&lt;/b&gt;=&lt;font color="#0000ff"&gt;&amp;quot;javascript:Init()&amp;quot;&lt;/font&gt;&amp;gt;
&lt;b&gt;&amp;lt;div&lt;/b&gt; &lt;b&gt;id&lt;/b&gt;=&lt;font color="#0000ff"&gt;&amp;quot;box&amp;quot;&lt;/font&gt;&amp;gt;&lt;b&gt;&amp;lt;img&lt;/b&gt; &lt;b&gt;class&lt;/b&gt;=&lt;font color="#0000ff"&gt;&amp;quot;image&amp;quot;&lt;/font&gt; &lt;b&gt;id&lt;/b&gt;=&lt;font color="#0000ff"&gt;&amp;quot;img1&amp;quot;&lt;/font&gt; &lt;b&gt;src&lt;/b&gt;=&lt;font color="#0000ff"&gt;&amp;quot;ball.png&amp;quot;&lt;/font&gt;/&amp;gt;&lt;b&gt;&amp;lt;/div&lt;/b&gt;&amp;gt;
&lt;b&gt;&amp;lt;a&lt;/b&gt; &lt;b&gt;href&lt;/b&gt;=&lt;font color="#0000ff"&gt;&amp;quot;javascript:moveLeft()&amp;quot;&lt;/font&gt;&amp;gt;Left&lt;b&gt;&amp;lt;/a&lt;/b&gt;&amp;gt;
&lt;b&gt;&amp;lt;a&lt;/b&gt; &lt;b&gt;href&lt;/b&gt;=&lt;font color="#0000ff"&gt;&amp;quot;javascript:moveUp()&amp;quot;&lt;/font&gt;&amp;gt;Up&lt;b&gt;&amp;lt;/a&lt;/b&gt;&amp;gt;
&lt;b&gt;&amp;lt;a&lt;/b&gt; &lt;b&gt;href&lt;/b&gt;=&lt;font color="#0000ff"&gt;&amp;quot;javascript:moveDown()&amp;quot;&lt;/font&gt;&amp;gt;Down&lt;b&gt;&amp;lt;/a&lt;/b&gt;&amp;gt;
&lt;b&gt;&amp;lt;a&lt;/b&gt; &lt;b&gt;href&lt;/b&gt;=&lt;font color="#0000ff"&gt;&amp;quot;javascript:moveRight()&amp;quot;&lt;/font&gt;&amp;gt;Right&lt;b&gt;&amp;lt;/a&lt;/b&gt;&amp;gt;
&lt;b&gt;&amp;lt;/body&lt;/b&gt;&amp;gt;
&lt;b&gt;&amp;lt;/html&lt;/b&gt;&lt;/font&gt;&amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;NOTE: An image with name &amp;quot;ball.png&amp;quot; must be there in the same directory as this file for the above ocde to work &amp;quot;as-is&amp;quot;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Related Posts:&lt;/strong&gt;
&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/08/creating-simple-countdown-timer-using_14.html"&gt;Creating a Simple Countdown Timer Using JavaScript II...Using getElementById() Method&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/08/creating-simple-countdown-timer-using.html"&gt;Creating a Simple Countdown Timer Using JavaScript&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/06/creating-simple-html-form-validation.html"&gt;Creating a Simple HTML Form Validation System Using JavaScript&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/33629562-4848397658779681995?l=learning-computer-programming.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TiGWE/~4/7RXEar_mrvA" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://learning-computer-programming.blogspot.com/feeds/4848397658779681995/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://learning-computer-programming.blogspot.com/2009/09/moving-positioning-image-using.html#comment-form" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/33629562/posts/default/4848397658779681995?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/33629562/posts/default/4848397658779681995?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/TiGWE/~3/7RXEar_mrvA/moving-positioning-image-using.html" title="Moving (Positioning) an Image Using JavaScript" /><author><name>Arvind Gupta</name><uri>http://www.blogger.com/profile/17199066124402939022</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="23" height="32" src="http://one.arvind.googlepages.com/arvind_gupta_photo.jpg" /></author><thr:total>2</thr:total><feedburner:origLink>http://learning-computer-programming.blogspot.com/2009/09/moving-positioning-image-using.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CUMAQH4zfSp7ImA9WxVUGU4.&quot;"><id>tag:blogger.com,1999:blog-33629562.post-6421500131166918135</id><published>2009-03-25T03:54:00.000+05:30</published><updated>2009-03-25T03:54:01.085+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-03-25T03:54:01.085+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="PHP" /><category scheme="http://www.blogger.com/atom/ns#" term="Methods" /><category scheme="http://www.blogger.com/atom/ns#" term="Example Programs" /><category scheme="http://www.blogger.com/atom/ns#" term="Image Generation" /><category scheme="http://www.blogger.com/atom/ns#" term="Useful Scripts" /><category scheme="http://www.blogger.com/atom/ns#" term="Tricks" /><category scheme="http://www.blogger.com/atom/ns#" term="Complete Script" /><category scheme="http://www.blogger.com/atom/ns#" term="Image" /><title>Image Generation Using PHP</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/ahZ9wojRJNGOvE6MPJsBX2VflEE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ahZ9wojRJNGOvE6MPJsBX2VflEE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/ahZ9wojRJNGOvE6MPJsBX2VflEE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ahZ9wojRJNGOvE6MPJsBX2VflEE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;img style="width: 200px; height: 200px;"
alt="Image Generation Using PHP"
title="A Sample Image Generated Using Our Script"
src="http://one.arvind.googlepages.com/php_image_generation.png"&gt;&lt;/p&gt;
&lt;p&gt;
In one of the previous posts about &lt;a style="font-style: italic;"
href="http://learning-computer-programming.blogspot.com/2009/03/how-captcha-works-and-simple-script-in.html"&gt;CAPTCHA
Image Generation&lt;/a&gt; we made use of PHP’s image generation functions
but didn’t discuss about them. So, if you had any problems or just want
to know more, read on.&lt;br&gt;
&lt;/p&gt;
&lt;p&gt;Creating and outputting images from PHP is very simple and easy. And
since PHP supports images in a number of different formats you can very
easily generate images in various formats such as JPEG, PNG, GIF etc.
Generating&amp;nbsp; images involves the following steps:&lt;br&gt;
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Creating a canvas.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Drawing&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Outputting the image.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Now, let’s look at each of the steps in detail.&lt;br&gt;
&lt;/p&gt;
&lt;h2&gt;Creating a Canvas&lt;br&gt;
&lt;/h2&gt;
&lt;p&gt;Creating a canvas is very easy, just use the following function:&lt;br&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;resource&amp;nbsp;ImageCreateTrueColor&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;(&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;int&amp;nbsp;$width&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;int&amp;nbsp;$height&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;)&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The capitalization doesn’t matter as with any function in PHP.&lt;br&gt;
&lt;/p&gt;
&lt;p&gt;If you want your canvas to have some background color (default is
black) you can use the following function:&lt;br&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;bool&amp;nbsp;ImageFill&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;(&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;resource&amp;nbsp;$image&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;int&amp;nbsp;$x&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;int&amp;nbsp;$y&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;int&amp;nbsp;$color&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Where color is to be first allocate using the following function:&lt;br&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;int&amp;nbsp;ImageColorAllocate&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;(&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;resource&amp;nbsp;$image&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;int&amp;nbsp;$red&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;int&amp;nbsp;$green&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;int&amp;nbsp;$blue&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You can also use an existing image as base canvas for your new
image,
in that case create your image using the following function:&lt;br&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;resource ImageCreateFromJPEG &lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;(&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;string&amp;nbsp;$filename&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Images in other format can also be used, for PNG →&amp;nbsp; &lt;code&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;ImageCreateFromPNG &lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;()&lt;/span&gt;&lt;/code&gt;, GIF → &lt;code&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;ImageCreateFromGIF &lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;()&lt;/span&gt;&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;
&lt;h2&gt;Drawing&lt;/h2&gt;
&lt;p&gt;After having set up the canvas, let’s draw something on it, say, a
rectangle. The rectangle drawing function with its argument list is:&lt;br&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;bool ImageRectangle&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;(&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;resource&amp;nbsp;$image&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;int&amp;nbsp;$x1&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;int&amp;nbsp;$y1&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;int&amp;nbsp;$x2&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;int&amp;nbsp;$y2&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;int&amp;nbsp;$color&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;For allocating color use the &lt;code&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;ImageColorAllocate&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;()&lt;/span&gt;&lt;/code&gt; function.&lt;br&gt;
&lt;/p&gt;
&lt;p&gt;The following will create a square of size 10px X 10px having a blue
border:&lt;br&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$img&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;=&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;ImageCreateTrueColor&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;20&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;, 20&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt;&lt;span
style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$blue&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;=&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;ImageColorAllocate&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$img&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;255&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;);&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;&lt;/span&gt;&lt;span
style="color: rgb(255, 128, 0);"&gt;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;ImageRectangle&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$img&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;10&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;10&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$blue&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You can browse the complete list of &lt;a style="font-style: italic;"
href="http://in.php.net/manual/en/ref.image.php"&gt;drawing (GD)
functions in PHP
here&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;
&lt;p&gt;Some of the common ones are:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;code&gt;bool ImageLine &lt;/code&gt;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;( &lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;resource $image &lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;int $x1 &lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;int $y1 &lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;int $x2 &lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;int $y2 &lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;int $color &lt;/span&gt;)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;bool ImageEllipse&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;(&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;resource&amp;nbsp;$image&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;int&amp;nbsp;$cx&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;int&amp;nbsp;$cy&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;int&amp;nbsp;$width&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;int&amp;nbsp;$height&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;int&amp;nbsp;$color&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;)&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;bool ImageArc&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;(&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;resource&amp;nbsp;$image&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;int&amp;nbsp;$cx&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;int&amp;nbsp;$cy&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;int&amp;nbsp;$width&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;int&amp;nbsp;$height&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;int&amp;nbsp;$start&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;int&amp;nbsp;$end&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;int&amp;nbsp;$color&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;br&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
I think we should also discuss a little about one function, to draw
text on out image, it’s called the &lt;code&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;ImageString&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;()&lt;/span&gt;&lt;/code&gt; function having the
following form:&lt;br&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;bool ImageString&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;(&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;resource&amp;nbsp;$image&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;int&amp;nbsp;$font&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;int&amp;nbsp;$x&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;int&amp;nbsp;$y&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;string&amp;nbsp;$string&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;int&amp;nbsp;$color&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;)&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Example:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$img&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;=&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;ImageCreateTrueColor&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;100&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;, &lt;span style="color: rgb(0, 0, 187);"&gt;100&lt;/span&gt;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;br&gt;&lt;code&gt;&lt;span
style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$red&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;=&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;ImageColorAllocate&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$img&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;255&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;);&lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span
style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;ImageString&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$img&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;7&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;10&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;10&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(221, 0, 0);"&gt;'Text'&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$red&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;);&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;ImageString&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$img&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;5&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;10&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt; &lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;30&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(221, 0, 0);"&gt;'Smaller Text'&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$red&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;br&gt;&lt;/pre&gt;
&lt;p&gt;
The above lines will draw two string of text and the first one will
have a bigger font size. Higher number fonts (for &lt;code&gt;$font&lt;/code&gt;)
are bigger.&lt;br&gt;
&lt;/p&gt;
&lt;p&gt;All done,now we have a completed image that just needs to be sent to
the browser. For this we first need to tell the browser what type of
content we’re going to send and the data (image) itself. The following
two lines will do this:&lt;br&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;header&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
style="color: rgb(221, 0, 0);"&gt;'Content-Type:&amp;nbsp;image/png'&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;);&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;ImagePNG&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$img&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Similarly you can output image in other formats also, just replace &lt;code&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;ImageJPEG&lt;/span&gt;&lt;/code&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt; with &lt;code&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;ImageGIF&lt;/span&gt;&lt;/code&gt; or &lt;code&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;ImagePNG&lt;/span&gt;&lt;/code&gt; etc. and the &lt;code&gt;content-type&lt;/code&gt;
header to &lt;code&gt;image/gif&lt;/code&gt; or &lt;code&gt;image/png&lt;/code&gt;
accordingly.&lt;br&gt;
&lt;/p&gt;
&lt;p&gt;After having output the image there is one more thing we should take
care of-freeing up the resources. You know images can take up
significant amount of resources which may affect the server and other
scripts running on it, so always use the following function:&lt;br&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;bool ImageDestroy&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;(&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;resource&amp;nbsp;$image&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The following example code illustrates all, what we have learnt:&lt;br&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;&amp;lt;?&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(255, 128, 0);"&gt;/********************************************************&lt;br&gt;&amp;nbsp;*&amp;nbsp;DESCRIPTION:&amp;nbsp;Exmple&amp;nbsp;program&amp;nbsp;to&amp;nbsp;illustrate&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;*&lt;br&gt;&amp;nbsp;*&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;image&amp;nbsp;generation&amp;nbsp;using&amp;nbsp;PHP.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;*&lt;br&gt;&amp;nbsp;*&amp;nbsp;AUTHOR:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Arvind&amp;nbsp;Gupta&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;*&lt;br&gt;&amp;nbsp;*&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(http://www.arvindgupta.co.in)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;*&lt;br&gt;&amp;nbsp;*&amp;nbsp;DATE:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;21-Mar-09&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;*&lt;br&gt;&amp;nbsp;*&amp;nbsp;WEBSITE:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;*&lt;br&gt;&amp;nbsp;*&amp;nbsp;http://learning-computer-programming.blogspot.com/&amp;nbsp;&amp;nbsp;&amp;nbsp;*&lt;br&gt;&amp;nbsp;********************************************************/&lt;br&gt;//&amp;nbsp;Set&amp;nbsp;width&amp;nbsp;and&amp;nbsp;height&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$width&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;=&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;200&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;;&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$height&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;=&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;200&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;;&lt;br&gt;&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(255, 128, 0);"&gt;//&amp;nbsp;Create&amp;nbsp;canvas&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$img&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;=&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;ImageCreateTrueColor&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$width&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$height&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;);&lt;br&gt;&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(255, 128, 0);"&gt;//&amp;nbsp;Allocate&amp;nbsp;colors&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$gray&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;=&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;ImageColorAllocate&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$img&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;200&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;200&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;200&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;);&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$red&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;=&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;ImageColorAllocate&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$img&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;255&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;);&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$green&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;=&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;ImageColorAllocate&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$img&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;255&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;);&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$blue&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;=&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;ImageColorAllocate&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$img&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;255&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;);&lt;br&gt;&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(255, 128, 0);"&gt;//&amp;nbsp;Fill&amp;nbsp;background&amp;nbsp;color&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;ImageFill&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$img&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$gray&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;);&lt;br&gt;&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(255, 128, 0);"&gt;//&amp;nbsp;Draw&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;ImageRectangle&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$img&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;5&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;5&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;(&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$width&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;-&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;5&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;),&amp;nbsp;(&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$height&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;-&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;5&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;),&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$red&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;);&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;ImageLine&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$img&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;5&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;5&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;(&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$width&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;-&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;5&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;),&amp;nbsp;(&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$height&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;-&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;5&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;),&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$red&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;);&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;ImageEllipse&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$img&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;(&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$width&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;/&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;2&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;),&amp;nbsp;(&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$height&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;/&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;2&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;),&amp;nbsp;(&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$width&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;-&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;10&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;),&amp;nbsp;(&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$height&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;-&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;10&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;),&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$green&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;);&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;ImageArc&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$img&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;(&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$width&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;/&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;2&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;),&amp;nbsp;(&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$height&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;/&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;2&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;),&amp;nbsp;(&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$width&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;-&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;40&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;),&amp;nbsp;(&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$height&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;-&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;40&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;),&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;180&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;360&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$blue&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;);&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;ImageArc&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$img&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;(&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$width&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;/&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;2&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;),&amp;nbsp;(&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$height&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;/&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;2&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;),&amp;nbsp;(&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$width&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;-&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;60&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;),&amp;nbsp;(&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$height&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;-&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;60&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;),&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;0&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;180&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$green&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;);&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;ImageString&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$img&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;7&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;(&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$width&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;/&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;2&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;)&amp;nbsp;-&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;50&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;(&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$height&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;/&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;2&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;)&amp;nbsp;-&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;10&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(221, 0, 0);"&gt;'Image&amp;nbsp;Created'&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$red&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;);&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;ImageString&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$img&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;7&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;(&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$width&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;/&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;2&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;)&amp;nbsp;-&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;30&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;(&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$height&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;/&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;2&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;)&amp;nbsp;+&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;10&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(221, 0, 0);"&gt;'Using&amp;nbsp;PHP'&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$green&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;);&lt;br&gt;&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(255, 128, 0);"&gt;//&amp;nbsp;Output&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;header&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
style="color: rgb(221, 0, 0);"&gt;'Content-Type:&amp;nbsp;image/png'&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;);&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;ImagePNG&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$img&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;);&lt;br&gt;&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(255, 128, 0);"&gt;//&amp;nbsp;Free-Up&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;ImageDestroy&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$img&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;);&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;NOTE: You need to enable the “gd2” extension from “php.ini” for all
this to work. See&lt;span style="text-decoration: underline;"&gt; &lt;/span&gt;&lt;a
style="font-style: italic;"
href="http://in.php.net/manual/en/image.setup.php"&gt;Installing/Configuring
Image Support in PHP&lt;/a&gt; for more information.
&lt;/p&gt;
&lt;p&gt;Okay, end of this post. Keep checking back for more.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/33629562-6421500131166918135?l=learning-computer-programming.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TiGWE/~4/zurxHSruveg" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://learning-computer-programming.blogspot.com/feeds/6421500131166918135/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://learning-computer-programming.blogspot.com/2009/03/image-generation-using-php.html#comment-form" title="12 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/33629562/posts/default/6421500131166918135?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/33629562/posts/default/6421500131166918135?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/TiGWE/~3/zurxHSruveg/image-generation-using-php.html" title="Image Generation Using PHP" /><author><name>Arvind Gupta</name><uri>http://www.blogger.com/profile/17199066124402939022</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="23" height="32" src="http://one.arvind.googlepages.com/arvind_gupta_photo.jpg" /></author><thr:total>12</thr:total><feedburner:origLink>http://learning-computer-programming.blogspot.com/2009/03/image-generation-using-php.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CUABR3w9cCp7ImA9WxVUFk4.&quot;"><id>tag:blogger.com,1999:blog-33629562.post-2173731002495102297</id><published>2009-03-18T16:17:00.003+05:30</published><updated>2009-03-21T16:39:16.268+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-03-21T16:39:16.268+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Web" /><category scheme="http://www.blogger.com/atom/ns#" term="PHP" /><category scheme="http://www.blogger.com/atom/ns#" term="XHTML" /><category scheme="http://www.blogger.com/atom/ns#" term="Example Programs" /><category scheme="http://www.blogger.com/atom/ns#" term="CAPTCHA" /><category scheme="http://www.blogger.com/atom/ns#" term="Securing" /><category scheme="http://www.blogger.com/atom/ns#" term="Useful Scripts" /><category scheme="http://www.blogger.com/atom/ns#" term="Tricks" /><category scheme="http://www.blogger.com/atom/ns#" term="Complete Script" /><category scheme="http://www.blogger.com/atom/ns#" term="HTML" /><title>How CAPTCHA Works? And a Simple Script in PHP</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/jU0s21U0rrA7OjSygv4EQ1vXyXU/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/jU0s21U0rrA7OjSygv4EQ1vXyXU/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/jU0s21U0rrA7OjSygv4EQ1vXyXU/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/jU0s21U0rrA7OjSygv4EQ1vXyXU/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p style="text-align: center;"&gt;&lt;big style="font-weight: bold;"&gt;&lt;big&gt;[&lt;/big&gt;&lt;/big&gt;For
this post I'm
presuming that you
are familiar with CAPTCHA, if not please read this&amp;nbsp;&lt;a
style="font-style: italic;" href="http://en.wikipedia.org/wiki/Captcha"
target="_blank"&gt;Introduction
to CAPTCHA&lt;/a&gt;&lt;big style="font-weight: bold;"&gt;&lt;big&gt;]&lt;/big&gt;&lt;/big&gt;&lt;/p&gt;
&lt;p&gt;&lt;img style="float: left;"
src="http://one.arvind.googlepages.com/generated_captcha.png"
alt="CAPTCHA Image Generated by Our Script"
title="CAPTCHA Image Generated by Our Script" height="53" width="150"&gt;Today
we are going to see
how CAPTCHA
(&lt;b&gt;C&lt;/b&gt;ompletely &lt;b&gt;A&lt;/b&gt;utomated &lt;b&gt;P&lt;/b&gt;ublic
&lt;b&gt;T&lt;/b&gt;uring test to tell &lt;b&gt;C&lt;/b&gt;omputers
and &lt;b&gt;H&lt;/b&gt;umans &lt;b&gt;A&lt;/b&gt;part) works and &lt;a
style="font-style: italic;"
href="http://computer.howstuffworks.com/captcha.htm" target="_blank"&gt;how
it minimizes&amp;nbsp;automatic sign-up
of
form&lt;/a&gt;&lt;a style="font-style: italic;"
href="http://computer.howstuffworks.com/captcha.htm" target="_blank"&gt;s&lt;/a&gt;.
We will also be creating a
simple CAPTCHA script in
PHP to illustrate this.&lt;/p&gt;
&lt;p&gt;Basically CAPTCHA works in
the
following manner:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Create Random Value:
Some random string is generated, random values are often hard to guess
and predict.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Generate an Image:
Images are used as these are generally a lot harder to read for
computers while being nice and readable to humans. This is also the
most important step as simple text in images can be read (and CAPTCHA
cracked) quite easily. To make it difficult for them, developers employ
different techniques so that the text in the image becomes hard to read
for computers. Some create zig-zag lines for background while others
twist-and-turn individual characters in the image. Possibilities are
many and new techniques are being developed all the time as crackers
are always into finding ways to break them.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Store it: The random
string generated (which is also in the image) is stored for matching
the user input. The easiest way to do so is to use the&amp;nbsp;&lt;a
style="font-style: italic;" href="http://in.php.net/session"
target="_blank"&gt;Session
variables&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Matching: After the
above step, the CAPTCHA image is generated and shown on some form which
we want to protect from being abused. The users fills in the form along
with the CAPTCHA text and submits it. Now we have the following:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;All submitted form
data.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;CAPTCHA string
(from form), input by user.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;CAPTCHA string
(real one, generated by us), from session variable. Session variable is
generally used as it can keep stored values across page requests. Here,
we needed to preserve stored values from one page (form page) to
another (action page-that receives form data).&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If both match, it's
okay otherwise not, in that case we can give the user a message that
the CAPTCHA they had entered was wrong and their form could not be
submitted. You could also ask them to verify it again.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The following image might
illustrates
this better:&lt;/p&gt;
&lt;p style="text-align: center;"&gt;&lt;img
src="http://one.arvind.googlepages.com/captch_generation_and_matching_STEPS.png"
alt="CAPTCHA Generation and Matching" align="middle" height="636"
width="417"&gt;&lt;br&gt;
How CAPTCHA is Generated and Matched&lt;/p&gt;
&lt;p&gt;From the above image it's
quite clear
that when someone requests the form page, the CAPTCHA text is
generated and sent back to requesting user, but only in the form of
an image. If the requester is a human he'd not have much difficulty
reading the image and inputting the text when asked but if it's a
bot it might face difficulties guessing whats in the image. In the
next step when we match the string generated and the one the user had
input, we can restrict automated form submissions.&lt;/p&gt;
&lt;p&gt;The following is the code that does this, it'll just output
the CAPTCHA image to the browser when the script is requested:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;&amp;lt;?php&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(255, 128, 0);"&gt;/********************************************************&lt;br&gt;&amp;nbsp;*&amp;nbsp;File:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;captcha.php&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;*&lt;br&gt;&amp;nbsp;*&amp;nbsp;Author:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Arvind&amp;nbsp;Gupta&amp;nbsp;(www.arvindgupta.co.in)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;*&lt;br&gt;&amp;nbsp;*&amp;nbsp;Date:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;12-Mar-2009&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;*&lt;br&gt;&amp;nbsp;*&amp;nbsp;Description:&amp;nbsp;This&amp;nbsp;file&amp;nbsp;can&amp;nbsp;be&amp;nbsp;embedded&amp;nbsp;as&amp;nbsp;image&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;*&lt;br&gt;&amp;nbsp;*&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;to&amp;nbsp;show&amp;nbsp;CAPTCHA/&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;*&lt;br&gt;&amp;nbsp;********************************************************/&lt;br&gt;&lt;br&gt;//&amp;nbsp;The&amp;nbsp;number&amp;nbsp;of&amp;nbsp;characters&amp;nbsp;you&lt;br&gt;//&amp;nbsp;want&amp;nbsp;your&amp;nbsp;CAPTCHA&amp;nbsp;text&amp;nbsp;to&amp;nbsp;have&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;define&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
style="color: rgb(221, 0, 0);"&gt;'CAPTCHA_STRENGTH'&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt; 5&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;);&lt;br&gt;&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(255, 128, 0);"&gt;/****************************&lt;br&gt;&amp;nbsp;*&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;INITIALISE&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;*&lt;br&gt;&amp;nbsp;****************************/&lt;br&gt;//&amp;nbsp;Tell&amp;nbsp;PHP&amp;nbsp;we're&amp;nbsp;going&amp;nbsp;to&amp;nbsp;use&lt;br&gt;//&amp;nbsp;Session&amp;nbsp;vars&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;session_start&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;();&lt;br&gt;&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(255, 128, 0);"&gt;//&amp;nbsp;Md5&amp;nbsp;to&amp;nbsp;generate&amp;nbsp;the&amp;nbsp;random&amp;nbsp;string&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$random_str&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;=&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;md5&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;microtime&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;());&lt;br&gt;&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(255, 128, 0);"&gt;//&amp;nbsp;Trim&amp;nbsp;required&amp;nbsp;number&amp;nbsp;of&amp;nbsp;characters&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$captcha_str&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;=&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;substr&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$random_str&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;CAPTCHA_STRENGTH&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;);&lt;br&gt;&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(255, 128, 0);"&gt;//&amp;nbsp;Allocate&amp;nbsp;new&amp;nbsp;image&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$width&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;=&amp;nbsp;(&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;CAPTCHA_STRENGTH&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt; * &lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;10&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;)+&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;10&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;;&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$height&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;=&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;20&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;;&lt;br&gt;&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$captcha_img&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;=&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;ImageCreate&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$width&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$height&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;);&lt;br&gt;&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(255, 128, 0);"&gt;// ALLOCATE COLORS&lt;br&gt;//&amp;nbsp;Background&amp;nbsp;color-black&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$back_color&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;=&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;ImageColorAllocate&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$captcha_img&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;);&lt;br&gt;&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(255, 128, 0);"&gt;//&amp;nbsp;Text&amp;nbsp;color-white&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$text_color&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;=&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;ImageColorAllocate&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$captcha_img&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;255&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;255&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;255&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;);&lt;br&gt;&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(255, 128, 0);"&gt;//&amp;nbsp;Line&amp;nbsp;color-red&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$line_color&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;=&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;ImageColorAllocate&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$captcha_img&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;255&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;);&lt;br&gt;&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(255, 128, 0);"&gt;/****************************&lt;br&gt;&amp;nbsp;*&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;DRAW&amp;nbsp;BACKGROUND&amp;nbsp;&amp;amp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;*&lt;br&gt;&amp;nbsp;*&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;LINES&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;*&lt;br&gt;&amp;nbsp;****************************/&lt;br&gt;//&amp;nbsp;Fill&amp;nbsp;background&amp;nbsp;color&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;ImageFill&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$captcha_img&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$back_color&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;);&lt;br&gt;&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(255, 128, 0);"&gt;//&amp;nbsp;Draw&amp;nbsp;lines&amp;nbsp;accross&amp;nbsp;the&amp;nbsp;x-axis&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;for(&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$i &lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;=&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt; 0&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$i &lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;&amp;lt; &lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span
style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$width&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span
style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt; $i&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt; +=&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt; 5&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;ImageLine&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$captcha_img&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$i&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$i&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;20&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt; $line_color&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;);&lt;br&gt;&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(255, 128, 0);"&gt;//&amp;nbsp;Draw&amp;nbsp;lines&amp;nbsp;accross&amp;nbsp;the&amp;nbsp;y-axis&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;for(&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$i &lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$i&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt; &amp;lt; &lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;20&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt; $i&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt; += &lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;5&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;ImageLine&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$captcha_img&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$i&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span
style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$width&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span
style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$i &lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt; $line_color&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;);&lt;br&gt;&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(255, 128, 0);"&gt;/****************************&lt;br&gt;&amp;nbsp;*&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;DRAW&amp;nbsp;AND&amp;nbsp;OUTPUT&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;*&lt;br&gt;&amp;nbsp;*&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;IMAGE&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;*&lt;br&gt;&amp;nbsp;****************************/&lt;br&gt;//&amp;nbsp;Draw&amp;nbsp;the&amp;nbsp;random&amp;nbsp;string&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;ImageString&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$captcha_img&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;5&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;5&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;2&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$captcha_str&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$text_color&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;);&lt;br&gt;&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(255, 128, 0);"&gt;//&amp;nbsp;Carry&amp;nbsp;the&amp;nbsp;data&amp;nbsp;(KEY)&amp;nbsp;through&amp;nbsp;session&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$_SESSION&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span
style="color: rgb(221, 0, 0);"&gt;'key'&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;]&amp;nbsp;=&amp;nbsp;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$captcha_str&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;;&lt;br&gt;&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(255, 128, 0);"&gt;//&amp;nbsp;Send&amp;nbsp;data&amp;nbsp;type&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;header&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
style="color: rgb(221, 0, 0);"&gt;"Content-type:&amp;nbsp;image/jpeg"&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;);&lt;br&gt;&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(255, 128, 0);"&gt;//&amp;nbsp;Output&amp;nbsp;image&amp;nbsp;to&amp;nbsp;browser&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;ImageJPEG&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$captcha_img&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;);&lt;br&gt;&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(255, 128, 0);"&gt;//&amp;nbsp;Free-Up&amp;nbsp;resources&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;ImageDestroy&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;$captcha_img&lt;/span&gt;&lt;span
style="color: rgb(0, 119, 0);"&gt;);&lt;br&gt;&lt;/span&gt;&lt;span
style="color: rgb(0, 0, 187);"&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Okay, this it for this, in
the next one
we'll integrate this CAPTCHA script into one form and see how it
works. Till then goodbye!&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/33629562-2173731002495102297?l=learning-computer-programming.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TiGWE/~4/EtT1DDQZErM" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://learning-computer-programming.blogspot.com/feeds/2173731002495102297/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://learning-computer-programming.blogspot.com/2009/03/how-captcha-works-and-simple-script-in.html#comment-form" title="7 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/33629562/posts/default/2173731002495102297?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/33629562/posts/default/2173731002495102297?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/TiGWE/~3/EtT1DDQZErM/how-captcha-works-and-simple-script-in.html" title="How CAPTCHA Works? And a Simple Script in PHP" /><author><name>Arvind Gupta</name><uri>http://www.blogger.com/profile/17199066124402939022</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="23" height="32" src="http://one.arvind.googlepages.com/arvind_gupta_photo.jpg" /></author><thr:total>7</thr:total><feedburner:origLink>http://learning-computer-programming.blogspot.com/2009/03/how-captcha-works-and-simple-script-in.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CUMFSH8_eyp7ImA9WxVUE0o.&quot;"><id>tag:blogger.com,1999:blog-33629562.post-787675231372463855</id><published>2009-03-14T15:45:00.001+05:30</published><updated>2009-03-18T16:20:19.143+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-03-18T16:20:19.143+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Web" /><category scheme="http://www.blogger.com/atom/ns#" term="XHTML" /><category scheme="http://www.blogger.com/atom/ns#" term="Example Programs" /><category scheme="http://www.blogger.com/atom/ns#" term="Atom" /><category scheme="http://www.blogger.com/atom/ns#" term="RSS" /><category scheme="http://www.blogger.com/atom/ns#" term="XML" /><category scheme="http://www.blogger.com/atom/ns#" term="HTML" /><category scheme="http://www.blogger.com/atom/ns#" term="Feeds" /><category scheme="http://www.blogger.com/atom/ns#" term="Classes" /><title>Generating XML Feeds (RSS, Atom) Using PHP</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/7lBaW0SbsNJ0Vyr0NtXn5Tgm0go/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/7lBaW0SbsNJ0Vyr0NtXn5Tgm0go/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/7lBaW0SbsNJ0Vyr0NtXn5Tgm0go/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/7lBaW0SbsNJ0Vyr0NtXn5Tgm0go/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;RSS/ATOM feeds are very common these days and almost all
Content Management Systems (CMS) can generate it. But in the case when
you want to generate it yourself or just want to learn how you can,
read on!&lt;/p&gt;
&lt;p&gt;Both RSS and ATOM feeds are written in eXtensible Markup
Language (XML)&amp;nbsp;standard markup. Not just standard markups, you
also need to be sure of what
and how you put data in those markup elements (tags). For all this
refer to the feed specifications of &lt;a
 href="http://cyber.law.harvard.edu/rss/rss.html" target="_blank"&gt;RSS&lt;/a&gt;
and &lt;a href="http://tools.ietf.org/html/rfc4287"
 target="_blank"&gt;ATOM&lt;/a&gt;. XML itself is very strict
and
the standard specifications makes it even harder to generate valid
feeds. And moreover, why re-invent the wheel when we can have it –
ready-made.&lt;/p&gt;
&lt;p&gt;The solution I'm referring to here is, to use a third-party
Library – Universal FeedWriter. FeedWriter is a PHP class written by
Anis uddin Ahmad that can dramatically&amp;nbsp; ease-off feeds (both
RSS and Atom) generation. You can download this library from&amp;nbsp;&lt;a
 href="http://www.phpclasses.org/browse/file/22275.html"
 target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Every feed should have at least the following data:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Feed title&lt;/li&gt;
  &lt;li&gt;URL(of the website whose feed is it)&lt;/li&gt;
  &lt;li&gt;Description&lt;/li&gt;
  &lt;li&gt;Item&lt;/li&gt;
  &lt;ol&gt;
    &lt;li&gt;Title&lt;/li&gt;
    &lt;li&gt;Date&lt;/li&gt;
    &lt;li&gt;URL (of the item, sometimes called permalink)&lt;/li&gt;
    &lt;li&gt;Description (body of the item)&lt;br&gt;
    &lt;/li&gt;
  &lt;/ol&gt;
&lt;/ol&gt;
&lt;p&gt;The RSS feed for this will look something like:&lt;/p&gt;
&lt;pre&gt;&amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt;&lt;br&gt;&amp;lt;rss version="2.0"&lt;br&gt;xmlns:content="http://purl.org/rss/1.0/modules/content/"&lt;br&gt;xmlns:wfw="http://wellformedweb.org/CommentAPI/"&amp;gt;&lt;br&gt;&lt;br&gt;&amp;lt;channel&amp;gt;&lt;br&gt;&amp;lt;title&amp;gt;RSS Title&amp;lt;/title&amp;gt;&lt;br&gt;&amp;lt;link&amp;gt;URL of Website&amp;lt;/link&amp;gt;&lt;br&gt;&amp;lt;description&amp;gt;&amp;lt;![CDATA[Description]]&amp;gt;&amp;lt;/description&amp;gt;&lt;br&gt;&amp;lt;language&amp;gt;en-us&amp;lt;/language&amp;gt;&lt;br&gt;&amp;lt;pubDate&amp;gt;Sat, 07 Mar 2009 06:55:15 +0530&amp;lt;/pubDate&amp;gt;&lt;br&gt;&lt;br&gt;&amp;lt;item&amp;gt;&lt;br&gt;&amp;lt;title&amp;gt;Item Title&amp;lt;/title&amp;gt;&lt;br&gt;&amp;lt;link&amp;gt;Item URL (Permalink)&amp;lt;/link&amp;gt;&lt;br&gt;&amp;lt;pubDate&amp;gt;Sat, 07 Mar 2009 06:55:15 +0530&amp;lt;/pubDate&amp;gt;&lt;br&gt;&amp;lt;description&amp;gt;&amp;lt;![CDATA[Item Description]]&amp;gt;&amp;lt;/description&amp;gt;&lt;br&gt;&amp;lt;/item&amp;gt;&lt;br&gt;&amp;lt;/channel&amp;gt;&lt;br&gt;&amp;lt;/rss&amp;gt;&lt;/pre&gt;
&lt;p&gt;Using FeddWriter abstracts working with and generating XML
tags manually, you just tell FeedWriter what kind of Feed (RSS/Atom and
version) you want; give it the data you want your feed to have and
you’re done! The following code snippet shows you how exactly:&lt;br&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;&amp;lt;?php&lt;br&gt;&lt;/span&gt;&lt;span
 style="color: rgb(255, 128, 0);"&gt;//&amp;nbsp;Include&amp;nbsp;the&amp;nbsp;class&lt;br&gt;&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;include(&lt;/span&gt;&lt;span
 style="color: rgb(221, 0, 0);"&gt;"FeedWriter.php"&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;);&lt;br&gt;&lt;br&gt;&lt;/span&gt;&lt;span
 style="color: rgb(255, 128, 0);"&gt;//&amp;nbsp;Creating&amp;nbsp;an&amp;nbsp;instance&amp;nbsp;of&amp;nbsp;FeedWriter&amp;nbsp;class.&lt;br&gt;//&amp;nbsp;The&amp;nbsp;parameter&amp;nbsp;tell&amp;nbsp;what&amp;nbsp;type&amp;nbsp;of&lt;br&gt;//&amp;nbsp;feed&amp;nbsp;you&amp;nbsp;want.&lt;br&gt;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;$MyFeed&amp;nbsp;&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;=&amp;nbsp;new&amp;nbsp;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;FeedWriter&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;RSS2&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;);&lt;br&gt;&lt;br&gt;&lt;/span&gt;&lt;span
 style="color: rgb(255, 128, 0);"&gt;//&amp;nbsp;Setting&amp;nbsp;feed&amp;nbsp;elements&lt;br&gt;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;$MyFeed&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;-&amp;gt;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;setTitle&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
 style="color: rgb(221, 0, 0);"&gt;'My&amp;nbsp;RSS&amp;nbsp;Feed'&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;);&lt;br&gt;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;$MyFeed&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;-&amp;gt;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;setLink&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
 style="color: rgb(221, 0, 0);"&gt;'http://www.example.com'&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;);&lt;br&gt;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;$MyFeed&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;-&amp;gt;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;setDescription&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
 style="color: rgb(221, 0, 0);"&gt;'Test&amp;nbsp;feed&amp;nbsp;generated&amp;nbsp;by&amp;nbsp;Universal&amp;nbsp;FeedWriter.'&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;);&lt;br&gt;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;$MyFeed&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;-&amp;gt;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;setChannelElement&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
 style="color: rgb(221, 0, 0);"&gt;'pubDate'&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;date&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;DATE_RSS&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;time&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;()));&lt;br&gt;&lt;br&gt;&lt;/span&gt;&lt;span
 style="color: rgb(255, 128, 0);"&gt;//&amp;nbsp;Create&amp;nbsp;a&amp;nbsp;FeedItem.&lt;br&gt;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;$Item&amp;nbsp;&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;=&amp;nbsp;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;$MyFeed&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;-&amp;gt;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;createNewItem&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;();&lt;br&gt;&lt;br&gt;&lt;/span&gt;&lt;span
 style="color: rgb(255, 128, 0);"&gt;//&amp;nbsp;Add&amp;nbsp;elements&amp;nbsp;to&amp;nbsp;the&amp;nbsp;feed&amp;nbsp;item.&lt;br&gt;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;$Item&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;-&amp;gt;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;setTitle&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
 style="color: rgb(221, 0, 0);"&gt;'Item&amp;nbsp;Title'&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;);&lt;br&gt;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;$Item&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;-&amp;gt;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;setLink&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
 style="color: rgb(221, 0, 0);"&gt;'http://www.example.com/item1.html'&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;);&lt;br&gt;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;$Item&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;-&amp;gt;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;setDate&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;mktime&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;10&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;,&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;20&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;,&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;,&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;3&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;,&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;6&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;,&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;2008&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;));&lt;br&gt;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;$Item&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;-&amp;gt;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;setDescription&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
 style="color: rgb(221, 0, 0);"&gt;'Item&amp;nbsp;Description.&amp;nbsp;Can&amp;nbsp;contain&amp;nbsp;&amp;lt;b&amp;gt;HTML&amp;lt;/b&amp;gt;.'&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;);&lt;br&gt;&lt;br&gt;&lt;/span&gt;&lt;span
 style="color: rgb(255, 128, 0);"&gt;//&amp;nbsp;Now&amp;nbsp;add&amp;nbsp;the&amp;nbsp;item&amp;nbsp;to&amp;nbsp;the&amp;nbsp;feed.&lt;br&gt;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;$MyFeed&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;-&amp;gt;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;addItem&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;$Item&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;);&lt;br&gt;&lt;br&gt;&lt;/span&gt;&lt;span
 style="color: rgb(255, 128, 0);"&gt;//&amp;nbsp;Now&amp;nbsp;genarate&amp;nbsp;the&amp;nbsp;feed.&lt;br&gt;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;$MyFeed&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;-&amp;gt;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;genarateFeed&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;();&lt;br&gt;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;p&gt;So you see how easy it is to generate a feed with the data we
had.&lt;/p&gt;
&lt;p&gt;Feeds generally don’t just have one item so let’s see
something more
real. The following code will generate a feed having ten items:&lt;br&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;&amp;lt;?php&lt;br&gt;&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;include(&lt;/span&gt;&lt;span
 style="color: rgb(221, 0, 0);"&gt;"FeedWriter.php"&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;);&lt;br&gt;&lt;br&gt;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;$MyFeed&amp;nbsp;&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;=&amp;nbsp;new&amp;nbsp;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;FeedWriter&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;RSS2&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;);&lt;br&gt;&lt;br&gt;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;$MyFeed&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;-&amp;gt;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;setTitle&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
 style="color: rgb(221, 0, 0);"&gt;'My&amp;nbsp;RSS&amp;nbsp;Feed'&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;);&lt;br&gt;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;$MyFeed&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;-&amp;gt;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;setLink&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
 style="color: rgb(221, 0, 0);"&gt;'http://www.example.com'&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;);&lt;br&gt;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;$MyFeed&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;-&amp;gt;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;setDescription&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
 style="color: rgb(221, 0, 0);"&gt;'Test&amp;nbsp;feed&amp;nbsp;having&amp;nbsp;Ten&amp;nbsp;Items.'&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;);&lt;br&gt;&lt;br&gt;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;$time&amp;nbsp;&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;=&amp;nbsp;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;mktime&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;10&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;10&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;3&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;5&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;2009&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;);&lt;br&gt;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;$MyFeed&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;-&amp;gt;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;setChannelElement&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
 style="color: rgb(221, 0, 0);"&gt;'pubDate'&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;date&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;DATE_RSS&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;$time&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;));&lt;br&gt;&lt;br&gt;for(&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;$i&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;=&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;;&amp;nbsp;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;$i&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;&amp;lt;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;10&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;;&amp;nbsp;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;$i&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;++)&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;$Item&amp;nbsp;&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;=&amp;nbsp;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;$MyFeed&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;-&amp;gt;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;createNewItem&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;();&lt;br&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;$Item&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;-&amp;gt;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;setTitle&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
 style="color: rgb(221, 0, 0);"&gt;'Item'&amp;nbsp;&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;.&amp;nbsp;(&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;$i&amp;nbsp;&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;+&amp;nbsp;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;1&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;)&amp;nbsp;.&amp;nbsp;&lt;/span&gt;&lt;span
 style="color: rgb(221, 0, 0);"&gt;'&amp;nbsp;Title'&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;);&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;$Item&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;-&amp;gt;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;setLink&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
 style="color: rgb(221, 0, 0);"&gt;'http://www.example.com/item'&amp;nbsp;&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;.&amp;nbsp;(&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;$i&amp;nbsp;&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;+&amp;nbsp;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;1&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;)&amp;nbsp;.&amp;nbsp;&lt;/span&gt;&lt;span
 style="color: rgb(221, 0, 0);"&gt;'.html'&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;);&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span
 style="color: rgb(255, 128, 0);"&gt;//&amp;nbsp;Have&amp;nbsp;different&amp;nbsp;dates&amp;nbsp;for&amp;nbsp;each&amp;nbsp;item&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;Each&amp;nbsp;will&amp;nbsp;have&amp;nbsp;one&amp;nbsp;day&amp;nbsp;gap&amp;nbsp;for&amp;nbsp;the&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;publishing&amp;nbsp;time&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;$Item&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;-&amp;gt;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;setDate&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;$time&amp;nbsp;&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;-&amp;nbsp;(&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;$i&amp;nbsp;&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;*&amp;nbsp;(&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;24&amp;nbsp;&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;*&amp;nbsp;(&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;60&amp;nbsp;&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;*&amp;nbsp;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;60&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;))));&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;$Item&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;-&amp;gt;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;setDescription&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
 style="color: rgb(221, 0, 0);"&gt;'Item&amp;nbsp;'&amp;nbsp;&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;.&amp;nbsp;(&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;$i&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;+&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;1&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;)&amp;nbsp;.&amp;nbsp;&lt;/span&gt;&lt;span
 style="color: rgb(221, 0, 0);"&gt;'&amp;nbsp;Description.'&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;);&lt;br&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;$MyFeed&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;-&amp;gt;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;addItem&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;$Item&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;);&lt;br&gt;}&lt;br&gt;&lt;br&gt;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;$MyFeed&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;-&amp;gt;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;genarateFeed&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;();&lt;br&gt;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;One thing to note here is why we are using the feed’s
generation time to be same as&amp;nbsp; that of the latest item rather
than the current time when it is generated well, it’s because the feed
gets updated only as and when new items are added (remains same at
other time) and at the very same time. Therefore just because the feed
is being generated dynamically at each request doesn’t mean it is
“generate” at that time.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/33629562-787675231372463855?l=learning-computer-programming.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TiGWE/~4/H_fDxyRU4Wk" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://learning-computer-programming.blogspot.com/feeds/787675231372463855/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://learning-computer-programming.blogspot.com/2009/03/generating-xml-feeds-rss-atom-using-php.html#comment-form" title="3 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/33629562/posts/default/787675231372463855?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/33629562/posts/default/787675231372463855?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/TiGWE/~3/H_fDxyRU4Wk/generating-xml-feeds-rss-atom-using-php.html" title="Generating XML Feeds (RSS, Atom) Using PHP" /><author><name>Arvind Gupta</name><uri>http://www.blogger.com/profile/17199066124402939022</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="23" height="32" src="http://one.arvind.googlepages.com/arvind_gupta_photo.jpg" /></author><thr:total>3</thr:total><feedburner:origLink>http://learning-computer-programming.blogspot.com/2009/03/generating-xml-feeds-rss-atom-using-php.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CUAMQXw4fCp7ImA9WxVVEE0.&quot;"><id>tag:blogger.com,1999:blog-33629562.post-3731949106322258553</id><published>2009-03-02T19:53:00.000+05:30</published><updated>2009-03-02T19:53:00.234+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-03-02T19:53:00.234+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Web" /><category scheme="http://www.blogger.com/atom/ns#" term="IDE" /><category scheme="http://www.blogger.com/atom/ns#" term="PHP" /><category scheme="http://www.blogger.com/atom/ns#" term="XHTML" /><category scheme="http://www.blogger.com/atom/ns#" term="Software" /><category scheme="http://www.blogger.com/atom/ns#" term="CSS" /><category scheme="http://www.blogger.com/atom/ns#" term="HTML" /><title>Geany - A Good Web Development Editor (IDE)</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/jfD5C19XWjcATs8hLkIPnVZI-58/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/jfD5C19XWjcATs8hLkIPnVZI-58/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/jfD5C19XWjcATs8hLkIPnVZI-58/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/jfD5C19XWjcATs8hLkIPnVZI-58/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p style="text-align: center;"&gt;&lt;a
 href="http://geany.org/"&gt;&lt;img
 style="border: 0px solid ; width: 400px; height: 287px;"
 alt="Geany Version 0.16" title="Screenshot of Geany"
 src="http://one.arvind.googlepages.com/geany_screenshot.jpg"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p style="text-align: center;"&gt;&lt;a
 href="http://geany.org/" target="_blank"&gt;Geany
Homepage&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Last year I finally made a switch to GNU/Linux as my operating
system and had been in search of a good editor for my web development.
In Windows I used Dreamweaver for the purpose and was quite happy with
it. It could can easily highlight PHP, HTML, JavaScript and other codes
of some other languages related to web. It can also do some
Auto-Completion – a feature I think is a must-have. I also liked the
fact that it (version MX) was reasonably light on system resources.&lt;/p&gt;
&lt;p&gt;When I switched to Linux, I tried Bluefish, Komodo Edit,
Netbeans IDE. Bluefish (ver 1.0.7) had&amp;nbsp; a&amp;nbsp; bad syntax
highlighting feature besides other things I found to be quite irritable
(working with PHP files, at least). Komodo Edit and Netbeans stood out
especially Komodo Edit, in terms of functionality, usability and other
small-small things. But still these were not what I was looking for. I
wanted something good in terms of functionality but at the same time
light on resources (Komodo Edit took about 15 seconds to load). I
wanted something that had a good balance between features and memory
footprint.&lt;/p&gt;
&lt;p&gt;Geany is small (source package is about 2.2 MB), light on
resources and at the same time loaded with functionality and ease of
use for the size. Geany does not have all the features of a
full-fledged IDE (like for example Komodo Edit) but it has got many of
the important ons. And it's not just PHP and web development that you
can use it for, it has support for a good number of languages
(programming, scripting etc). But as I've only used it for web
development, I'm strictly talking in that context throughout.&lt;/p&gt;
&lt;p&gt;Here are some of the features I find very helpful:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;AutoComplete: For functions(inbuilt as well as
user-defined), variables, classes etc. Inbuilt functions are shown with
their argument list-very useful. And there's but only a few functions I
couldn't find in its database. Just type in a few characters and it
shows a nice drop-down list of suggestions, select one and it shows the
function's parameters list and their types. TIP: By default you need to
type in at least three characters for it to give you suggestions for
AutoComplete(ion) but it can be changes from
Edit-&amp;gt; Preferences-&amp;gt; Edit(Side-Tab)-&amp;gt;
Completions(Tab).
I personally have set it to be 1. &lt;br&gt;
    &lt;/p&gt;
    &lt;div style="text-align: center;"&gt;&lt;img
 style="width: 237px; height: 214px;"
 alt="Geany: Auto-Complete Feature"
 src="http://one.arvind.googlepages.com/auto_complete_feature.jpg"&gt;&lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Compile and Make: You can't “make” a PHP script but
compile is damn good a feature. Now forget refreshing the browser.
NOTE: Can only check syntax errors.&lt;br&gt;
    &lt;/p&gt;
    &lt;div style="text-align: center;"&gt;&lt;img
 style="width: 311px; height: 75px;" alt="Geany: Compile Feature"
 src="http://one.arvind.googlepages.com/compile_feature.jpg"
 align="middle"&gt;&lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Code-folding: Another
useful feature especially for
lengthy scripts.&lt;br&gt;
    &lt;/p&gt;
    &lt;div style="text-align: center;"&gt;
    &lt;img style="width: 340px; height: 253px;"
 alt="Geany: Code Folding"
 src="http://one.arvind.googlepages.com/code_folding.png"&gt;&lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Auto-Closing: Can close (X)HTML tags, parenthesis, curly
braces, quotes etc. for you. Check
Edit-&amp;gt;Preferences-&amp;gt;Edit(Side-Tab)-&amp;gt;Completions(Tab)
for settings.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Sidebar: These are many tabs in the sidebar but one of
them particularly stands ot. The one which displays “Symbols” in the
document-variables, functions, classes, objects, constants tec. This
one reminds me of the commercial IDEs such as Visual Studio. Just click
on something to find its declaration.&lt;br&gt;
    &lt;/p&gt;
    &lt;div style="text-align: center;"&gt;&lt;img
 style="width: 232px; height: 401px;" alt="Geany: Sidebar"
 src="http://one.arvind.googlepages.com/geany_sidebar.jpg"&gt;&lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Sessions: Just like Firefox can restore sessions of open
tabs(websites), Geany can restore session of files. If I'm working on,
say, ten files and I decide to go take a bath. I can close and shutdown
my PC because Geany will open all the files for me the next time I run
it. Great!&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Pre-defined Comments: Whether you want to insert copyright
note or license information or just function information. Just right
click and and got to “Insert Comments” menu, you have them just a click
away! There also exist a&amp;nbsp; feature for inserting current date
and time, for that go to “Insert Date” from the right -click menu.
Useful!&lt;br&gt;
    &lt;/p&gt;
    &lt;div style="text-align: center;"&gt;&lt;img
 style="width: 375px; height: 131px;"
 alt="Geany: Pre-Defined Comments"
 src="http://one.arvind.googlepages.com/pre_defined_comments.jpg"&gt;&lt;/div&gt;
    &lt;p&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Windows Version: Don't want to switch to Linux yet! No
problem! Just download the windows version (needs GTK libraries
installed)&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;In spite so many useful features there is one more thing I
expect Geany to do – better support for HTML files. Look, PHP and HTML
go hand-in-hand and I'd have loved to have HTML preview feature like
Dreamweaver has. We often embed PHP in HTML pages and Dreamweaver works
perfectly well for these kind of pages. This is where I miss my old
Dreamweaver the most.&amp;nbsp; I'm not saying this is Geany's
short-coming as it's designed not just for web development, but when
you do web development you'll&amp;nbsp; feel it's missing.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Some might wonder why I'm always mentioning Dreamweaver. This
is because unlike some of the editors I've used, it isn't just
restricted to HTML pages-it can handle dynamic content as well. Web
development isn't just HTML or PHP or ASP, it's a mix which Dreamweaver
handles quite well. It's a great HTML editor as well as it's a
quite-great PHP editor, this is what I love about it.&lt;/p&gt;
&lt;p
 style="border: 3px dashed rgb(0, 0, 255); padding: 20px; margin-right: 50px; margin-left: 50px; text-align: center;"&gt;&lt;a
 href="http://geany.org/" target="_blank"&gt;Geany
Homepage&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
&lt;a href="http://www.geany.org/Download/Releases"
 target="_blank"&gt;Geany
Download Page&lt;/a&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/33629562-3731949106322258553?l=learning-computer-programming.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TiGWE/~4/phXmf-qSCwQ" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://learning-computer-programming.blogspot.com/feeds/3731949106322258553/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://learning-computer-programming.blogspot.com/2009/03/geany-good-web-development-editor-ide.html#comment-form" title="8 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/33629562/posts/default/3731949106322258553?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/33629562/posts/default/3731949106322258553?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/TiGWE/~3/phXmf-qSCwQ/geany-good-web-development-editor-ide.html" title="Geany - A Good Web Development Editor (IDE)" /><author><name>Arvind Gupta</name><uri>http://www.blogger.com/profile/17199066124402939022</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="23" height="32" src="http://one.arvind.googlepages.com/arvind_gupta_photo.jpg" /></author><thr:total>8</thr:total><feedburner:origLink>http://learning-computer-programming.blogspot.com/2009/03/geany-good-web-development-editor-ide.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEIERH09eSp7ImA9WxVWE0U.&quot;"><id>tag:blogger.com,1999:blog-33629562.post-535129955429693526</id><published>2009-02-23T16:23:00.000+05:30</published><updated>2009-02-23T16:25:05.361+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-02-23T16:25:05.361+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="PHP" /><category scheme="http://www.blogger.com/atom/ns#" term="Methods" /><category scheme="http://www.blogger.com/atom/ns#" term="XHTML" /><category scheme="http://www.blogger.com/atom/ns#" term="WAP" /><category scheme="http://www.blogger.com/atom/ns#" term="Tricks" /><category scheme="http://www.blogger.com/atom/ns#" term="Introduction" /><category scheme="http://www.blogger.com/atom/ns#" term="HTML" /><title>Generating XHTML MP (WAP 2.0) Pages From PHP</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/8FvTWCoZfssfbx4NODBwi4dSKdg/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/8FvTWCoZfssfbx4NODBwi4dSKdg/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/8FvTWCoZfssfbx4NODBwi4dSKdg/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/8FvTWCoZfssfbx4NODBwi4dSKdg/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;img style="width: 240px; height: 180px; float: left;"
 alt="XHTML Mp Webpage Generation Using PHP"
 title="XHTML MP (WAP 2.0) Webpage on a Cellphone"
 src="http://one.arvind.googlepages.com/xhtml_mp_wap_site.jpg"&gt;Maybe
you guys know that I've been working on a service called
MyWapBlog.com which lets peoples create/manage mobile blogs using their
mobile phones. In the course of the development I've learnt great deal
about mobile websites and their dynamic generation, and I'm sharing a
bit of it here in this post.&lt;/p&gt;
&lt;p&gt;How do you generate dynamic (X)HTML Pages using PHP? Simple:&lt;/p&gt;
&lt;pre&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;br&gt;&amp;lt;!DOCTYPE&amp;nbsp;html&amp;nbsp;PUBLIC&amp;nbsp;"-//W3C//DTD&amp;nbsp;XHTML&amp;nbsp;1.0&amp;nbsp;Transitional//EN"&amp;nbsp;"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&amp;gt;&lt;br&gt;&amp;lt;html&amp;nbsp;xmlns="http://www.w3.org/1999/xhtml"&amp;nbsp;&amp;nbsp;dir="ltr"&amp;gt;&lt;br&gt;&amp;lt;head&amp;gt;&lt;br&gt;&amp;lt;title&amp;gt;Sometitle&amp;lt;/title&amp;gt;&lt;br&gt;&amp;lt;/head&amp;gt;&lt;br&gt;&amp;lt;body&amp;gt;&lt;br&gt;&amp;lt;h1&amp;gt;Hello&amp;lt;/h1&amp;gt;&lt;br&gt;&amp;lt;p&amp;gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;&amp;lt;?php&amp;nbsp;&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;echo&amp;nbsp;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;date&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
 style="color: rgb(221, 0, 0);"&gt;'h:i&amp;nbsp;A,&amp;nbsp;j-M-y'&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;);&amp;nbsp;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;?&amp;gt;&lt;/span&gt;&amp;lt;/p&amp;gt;&lt;br&gt;&amp;lt;/body&amp;gt;&lt;br&gt;&amp;lt;/html&amp;gt;&lt;br&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;And if you look at XHTML MP pages, their source look like the
following:&lt;/p&gt;
&lt;pre id="line1"&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;&lt;br&gt;&amp;lt;!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd"&amp;gt;&lt;br&gt;&amp;lt;html xmlns="http://www.w3.org/1999/xhtml"&amp;gt;&lt;br&gt;&lt;br&gt;&amp;lt;head&amp;gt;&lt;br&gt;...&lt;br&gt;...&lt;/pre&gt;
&lt;p&gt;So you see these pages have a different document type and some
other differences. So will the following code work and generate a valid
WAP 2.0 page?:&lt;/p&gt;
&lt;pre&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&amp;lt;?xml&amp;nbsp;version="1.0"&amp;nbsp;encoding="UTF-8"?&amp;gt;&lt;br&gt;&amp;lt;!DOCTYPE&amp;nbsp;html&amp;nbsp;PUBLIC&amp;nbsp;"-//WAPFORUM//DTD&amp;nbsp;XHTML&amp;nbsp;Mobile&amp;nbsp;1.0//EN"&amp;nbsp;"http://www.wapforum.org/DTD/xhtml-mobile10.dtd"&amp;gt;&lt;br&gt;&amp;lt;html&amp;nbsp;xmlns="http://www.w3.org/1999/xhtml"&amp;gt;&lt;br&gt;&amp;lt;head&amp;gt;&lt;br&gt;&amp;lt;title&amp;gt;Sometitle&amp;lt;/title&amp;gt;&lt;br&gt;&amp;lt;/head&amp;gt;&lt;br&gt;&amp;lt;body&amp;gt;&lt;br&gt;&amp;lt;h1&amp;gt;Hello&amp;lt;/h1&amp;gt;&lt;br&gt;&amp;lt;p&amp;gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;&amp;lt;?php&amp;nbsp;&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;echo&amp;nbsp;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;date&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
 style="color: rgb(221, 0, 0);"&gt;'h:i&amp;nbsp;A,&amp;nbsp;j-M-y'&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;);&amp;nbsp;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;?&amp;gt;&lt;/span&gt;&amp;lt;/p&amp;gt;&lt;br&gt;&amp;lt;/body&amp;gt;&lt;br&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;The answer is “NO”? Why? Because XHTML MP pages needs to be
served with a different Content-Type than what is generated by .PHP
files. Normally when you runa s PHP script and it outputs something,
the content is served with Content-Type: text/html&lt;/p&gt;
&lt;p style="font-weight: bold;"&gt;&lt;big&gt;What is
Content-Type?&lt;/big&gt;&lt;/p&gt;
&lt;p&gt;It is a header (information about a particular resource)
returned to browser when it requests something from a server. When you
request an image, the server return the image with the header
image/png, image/jpeg etc. letting the browser know how the returned
content is to be interpreted.&lt;/p&gt;
&lt;p&gt;PHP scripts can return contents of any type (using
the&amp;nbsp;&lt;code&gt;header()&lt;/code&gt; function), from text to
images and PDFs to ZIPs. And therfore
if we want to generate&amp;nbsp; XHTML MP pages, it can even do that
without doubt.&lt;/p&gt;
&lt;p&gt;So what we need to do is, just change the above code a bit
adding a new line at the top so that the whole code look like the
following:&lt;/p&gt;
&lt;pre&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;br&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;&amp;lt;?php&amp;nbsp;header&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
 style="color: rgb(221, 0, 0);"&gt;"Content-type:&amp;nbsp;application/vnd.wap.xhtml+xml;&amp;nbsp;charset=UTF-8"&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;);&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span
 style="color: rgb(0, 0, 0);"&gt;&amp;lt;?xml&amp;nbsp;version="1.0"&amp;nbsp;encoding="UTF-8"?&amp;gt;&lt;br&gt;&amp;lt;!DOCTYPE&amp;nbsp;html&amp;nbsp;PUBLIC&amp;nbsp;"-//WAPFORUM//DTD&amp;nbsp;XHTML&amp;nbsp;Mobile&amp;nbsp;1.0//EN"&amp;nbsp;"http://www.wapforum.org/DTD/xhtml-mobile10.dtd"&amp;gt;&lt;br&gt;&amp;lt;html&amp;nbsp;xmlns="http://www.w3.org/1999/xhtml"&amp;gt;&lt;br&gt;&amp;lt;head&amp;gt;&lt;br&gt;&amp;lt;title&amp;gt;Sometitle&amp;lt;/title&amp;gt;&lt;br&gt;&amp;lt;/head&amp;gt;&lt;br&gt;&amp;lt;body&amp;gt;&lt;br&gt;&amp;lt;h1&amp;gt;Hello&amp;lt;/h1&amp;gt;&lt;br&gt;&amp;lt;p&amp;gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;&amp;lt;?php&amp;nbsp;&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;echo&amp;nbsp;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;date&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span
 style="color: rgb(221, 0, 0);"&gt;'h:i&amp;nbsp;A,&amp;nbsp;j-M-y'&lt;/span&gt;&lt;span
 style="color: rgb(0, 119, 0);"&gt;);&amp;nbsp;&lt;/span&gt;&lt;span
 style="color: rgb(0, 0, 187);"&gt;?&amp;gt;&lt;/span&gt;&amp;lt;/p&amp;gt;&lt;br&gt;&amp;lt;/body&amp;gt;&lt;br&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;This will tell the browser that the content we are going to
serve is of the type XHTML MP. We always use the charset UTF-8 for
these pages, which is also told to the requesting browser.&lt;/p&gt;
&lt;p&gt;Now the big question is, why we didn't do this for normal HTML
pages. Why didn't we have to tell the browser that content is of the
type “text/html” when it was so? Because PHP does it for us! Yes
whenever we output anything from PHP scripts, the PHP interpreter
outputs the default header (text/html) automatically. Just as the
PHP&amp;nbsp; interpreter finds anything in the script that needs to be
output, it first generates a header, the outputted content follows. For
example in the first script, the very first line (very first character
“&amp;lt;”) needs to be output to the browser. So before that, the PHP
interpreter sends a content type header (default – text/html).&lt;/p&gt;
&lt;p&gt;Therefore, when we had to output our content with a different
header we had to make sure that it is done before PHP does it
automatically. Two headers&amp;nbsp; cannot be valid.&lt;/p&gt;
&lt;p&gt;This is it for this post, do check back soon for more new
posts. Till then, good bye!&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/33629562-535129955429693526?l=learning-computer-programming.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TiGWE/~4/qA67jjDNmIY" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://learning-computer-programming.blogspot.com/feeds/535129955429693526/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://learning-computer-programming.blogspot.com/2009/02/generating-xhtml-mp-wap-20-pages-from.html#comment-form" title="4 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/33629562/posts/default/535129955429693526?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/33629562/posts/default/535129955429693526?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/TiGWE/~3/qA67jjDNmIY/generating-xhtml-mp-wap-20-pages-from.html" title="Generating XHTML MP (WAP 2.0) Pages From PHP" /><author><name>Arvind Gupta</name><uri>http://www.blogger.com/profile/17199066124402939022</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="23" height="32" src="http://one.arvind.googlepages.com/arvind_gupta_photo.jpg" /></author><thr:total>4</thr:total><feedburner:origLink>http://learning-computer-programming.blogspot.com/2009/02/generating-xhtml-mp-wap-20-pages-from.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CUcASH85fSp7ImA9WxRUEUs.&quot;"><id>tag:blogger.com,1999:blog-33629562.post-8709564340756548369</id><published>2008-11-20T12:05:00.000+05:30</published><updated>2008-11-20T12:07:29.125+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-11-20T12:07:29.125+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Web" /><category scheme="http://www.blogger.com/atom/ns#" term="PHP" /><category scheme="http://www.blogger.com/atom/ns#" term="Methods" /><category scheme="http://www.blogger.com/atom/ns#" term="Example Programs" /><category scheme="http://www.blogger.com/atom/ns#" term="Miscellaneous" /><category scheme="http://www.blogger.com/atom/ns#" term="Tricks" /><category scheme="http://www.blogger.com/atom/ns#" term="HTML" /><title>Custom Tags Parsing Using Regular Expressions</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/dffNYUmxPZeLtWv-u06pdd35OsU/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/dffNYUmxPZeLtWv-u06pdd35OsU/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/dffNYUmxPZeLtWv-u06pdd35OsU/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/dffNYUmxPZeLtWv-u06pdd35OsU/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;In the last post, we had created a &lt;a href="http://learning-computer-programming.blogspot.com/2008/10/basic-custom-tags-parsing-script.html"&gt;&lt;em&gt;simple 
  custom tag parsing script&lt;/em&gt;&lt;/a&gt; using PHP string functions. In this post, 
  we are going to continue our discussion on custom tag parsing but rather using 
  Regular Expressions. Here we will see how regular expressions can used to parse 
  strings, we will also see where to and where not to use Regular Expressions. 
  Before continuing, I expect that you have a working knowledge of Regular Expressions 
  if not please first check out &lt;em&gt;&lt;a href="http://www.developertutorials.com/tutorials/php/mastering-regular-expressions-in-php-050526/page1.html"&gt;this 
  websites&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Let us first create the previous custom tag parsing script using expressions:&lt;/p&gt;
&lt;code&gt;&lt;span style="color: #000000"&gt;
&amp;lt;form&amp;nbsp;name="form1"&amp;nbsp;method="get"&amp;nbsp;action=""&amp;gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;p&amp;gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;!--&amp;nbsp;textarea&amp;nbsp;should&amp;nbsp;display&amp;nbsp;previously&amp;nbsp;wriiten&amp;nbsp;text&amp;nbsp;--&amp;gt;

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;textarea&amp;nbsp;name="content"&amp;nbsp;cols="35"&amp;nbsp;rows="12"&amp;nbsp;id="content"&amp;gt;&lt;span style="color: #0000BB"&gt;&amp;lt;?&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;if&amp;nbsp;(isset(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$_GET&lt;/span&gt;&lt;span style="color: #007700"&gt;[&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'content'&lt;/span&gt;&lt;span style="color: #007700"&gt;]))&amp;nbsp;echo&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$_GET&lt;/span&gt;&lt;span style="color: #007700"&gt;[&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'content'&lt;/span&gt;&lt;span style="color: #007700"&gt;];&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;?&amp;gt;&lt;/span&gt;&amp;lt;/textarea&amp;gt;

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;/p&amp;gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;p&amp;gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;input&amp;nbsp;name="parse"&amp;nbsp;type="submit"&amp;nbsp;id="parse"&amp;nbsp;value="Parse"&amp;gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;/p&amp;gt;
&lt;br /&gt;&amp;lt;/form&amp;gt;
&lt;br /&gt;&lt;span style="color: #0000BB"&gt;&amp;lt;?
&lt;br /&gt;
&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #007700"&gt;if(isset(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$_GET&lt;/span&gt;&lt;span style="color: #007700"&gt;[&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'parse'&lt;/span&gt;&lt;span style="color: #007700"&gt;]))

&lt;br /&gt;{
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$content&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;=&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$_GET&lt;/span&gt;&lt;span style="color: #007700"&gt;[&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'content'&lt;/span&gt;&lt;span style="color: #007700"&gt;];
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #FF9900"&gt;//convert&amp;nbsp;newlines&amp;nbsp;in&amp;nbsp;the&amp;nbsp;text&amp;nbsp;to&amp;nbsp;HTML&amp;nbsp;"&amp;lt;br&amp;nbsp;/&amp;gt;"

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//required&amp;nbsp;to&amp;nbsp;keep&amp;nbsp;formatting&amp;nbsp;(newlines)
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$content&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;=&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;nl2br&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$content&lt;/span&gt;&lt;span style="color: #007700"&gt;);
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #FF9900"&gt;//PHP&amp;nbsp;function&amp;nbsp;'eregi_replace'&amp;nbsp;replaces&amp;nbsp;all&amp;nbsp;occurences&amp;nbsp;of&amp;nbsp;the&amp;nbsp;expression&amp;nbsp;with&amp;nbsp;the&amp;nbsp;one&amp;nbsp;mentioned

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//'\\1'&amp;nbsp;is&amp;nbsp;the&amp;nbsp;string&amp;nbsp;matched&amp;nbsp;(one&amp;nbsp;in&amp;nbsp;parentheses&amp;nbsp;'()'&amp;nbsp;in&amp;nbsp;the&amp;nbsp;regular&amp;nbsp;expression
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//it's&amp;nbsp;a&amp;nbsp;'eregi_replace'&amp;nbsp;thing&amp;nbsp;not&amp;nbsp;PHP's

&lt;br /&gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$content&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;=&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;eregi_replace&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'\.b\.(.+)\./b\.'&lt;/span&gt;&lt;span style="color: #007700"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'&amp;lt;strong&amp;gt;\\1&amp;lt;/strong&amp;gt;'&lt;/span&gt;&lt;span style="color: #007700"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$content&lt;/span&gt;&lt;span style="color: #007700"&gt;);
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$content&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;=&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;eregi_replace&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'\.i\.(.+)\./i\.'&lt;/span&gt;&lt;span style="color: #007700"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'&amp;lt;i&amp;gt;\\1&amp;lt;/i&amp;gt;'&lt;/span&gt;&lt;span style="color: #007700"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$content&lt;/span&gt;&lt;span style="color: #007700"&gt;);

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #FF9900"&gt;//now&amp;nbsp;the&amp;nbsp;variable&amp;nbsp;$content&amp;nbsp;contains&amp;nbsp;HTML&amp;nbsp;formatted&amp;nbsp;text
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//display&amp;nbsp;it
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;echo&amp;nbsp;&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'&amp;lt;hr&amp;nbsp;/&amp;gt;'&lt;/span&gt;&lt;span style="color: #007700"&gt;;

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;echo&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$content&lt;/span&gt;&lt;span style="color: #007700"&gt;;
&lt;br /&gt;}
&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;?&amp;gt;&lt;/span&gt;
&lt;/span&gt;
&lt;/code&gt;
&lt;p&gt;
  But should we use regular expressions here, answer is NO, because, first regular 
  expressions run slower and they add a fair bit of complexity where the same 
  thing could have been done easily using just string functions.&lt;/p&gt;
&lt;p&gt;The reason for me staring this post with something contradicting to the theme 
  of the post is because people tend to avoid regular expressions thinking that 
  the same thing can be done otherwise (I just gave them one more chance!). Well 
  it may be case sometimes but in many other cases where complex string manipulation 
  is required with efficiency there is but one choice, regular expressions. The 
  next example will illustrate this.&lt;/p&gt;
&lt;p&gt;For this example we will parse &amp;#8216;*&amp;#8217; (asterisk) and &amp;#8216;_&amp;#8217; 
  (underscore) for bolding and italicizing text (as in Google Talk / IM applications). 
  The following text:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;Hello *World*. Hello _World_.&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Will be parsed and displayed as:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;Hello &lt;strong&gt;World&lt;/strong&gt;. Hello &lt;em&gt;World&lt;/em&gt;.&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;It is quite obvious that both tags&amp;#8217; start and end tags are the same. 
  Now let us see how this can be implemented (using regular expressions).&lt;/p&gt;
&lt;code&gt;&lt;span style="color: #000000"&gt;
&amp;lt;form&amp;nbsp;name="form1"&amp;nbsp;method="get"&amp;nbsp;action=""&amp;gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;p&amp;gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;!--&amp;nbsp;textarea&amp;nbsp;should&amp;nbsp;display&amp;nbsp;previously&amp;nbsp;wriiten&amp;nbsp;text&amp;nbsp;--&amp;gt;

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;textarea&amp;nbsp;name="content"&amp;nbsp;cols="35"&amp;nbsp;rows="12"&amp;nbsp;id="content"&amp;gt;&lt;span style="color: #0000BB"&gt;&amp;lt;?&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;if&amp;nbsp;(isset(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$_GET&lt;/span&gt;&lt;span style="color: #007700"&gt;[&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'content'&lt;/span&gt;&lt;span style="color: #007700"&gt;]))&amp;nbsp;echo&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$_GET&lt;/span&gt;&lt;span style="color: #007700"&gt;[&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'content'&lt;/span&gt;&lt;span style="color: #007700"&gt;];&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;?&amp;gt;&lt;/span&gt;&amp;lt;/textarea&amp;gt;

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;/p&amp;gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;p&amp;gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;input&amp;nbsp;name="parse"&amp;nbsp;type="submit"&amp;nbsp;id="parse"&amp;nbsp;value="Parse"&amp;gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;/p&amp;gt;
&lt;br /&gt;&amp;lt;/form&amp;gt;
&lt;br /&gt;&lt;span style="color: #0000BB"&gt;&amp;lt;?
&lt;br /&gt;
&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #007700"&gt;if(isset(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$_GET&lt;/span&gt;&lt;span style="color: #007700"&gt;[&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'parse'&lt;/span&gt;&lt;span style="color: #007700"&gt;]))

&lt;br /&gt;{
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$content&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;=&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$_GET&lt;/span&gt;&lt;span style="color: #007700"&gt;[&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'content'&lt;/span&gt;&lt;span style="color: #007700"&gt;];
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #FF9900"&gt;//convert&amp;nbsp;newlines&amp;nbsp;in&amp;nbsp;the&amp;nbsp;text&amp;nbsp;to&amp;nbsp;HTML&amp;nbsp;"&amp;lt;br&amp;nbsp;/&amp;gt;"

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//required&amp;nbsp;to&amp;nbsp;keep&amp;nbsp;formatting&amp;nbsp;(newlines)
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$content&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;=&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;nl2br&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$content&lt;/span&gt;&lt;span style="color: #007700"&gt;);
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #FF9900"&gt;//match&amp;nbsp;anything&amp;nbsp;between&amp;nbsp;the&amp;nbsp;tags&amp;nbsp;but&amp;nbsp;not&amp;nbsp;the&amp;nbsp;tag&amp;nbsp;itself

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//otherwise&amp;nbsp;'*hello*&amp;nbsp;world&amp;nbsp;*hello*'
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//will&amp;nbsp;be&amp;nbsp;print&amp;nbsp;'hello*&amp;nbsp;world&amp;nbsp;*hello'&amp;nbsp;in&amp;nbsp;bold
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//and&amp;nbsp;not&amp;nbsp;'hello(in&amp;nbsp;bold)&amp;nbsp;world&amp;nbsp;hello(again&amp;nbsp;in&amp;nbsp;bold)'

&lt;br /&gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$content&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;=&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;eregi_replace&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'\*(.[^*]+)\*'&lt;/span&gt;&lt;span style="color: #007700"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'&amp;lt;strong&amp;gt;\\1&amp;lt;/strong&amp;gt;'&lt;/span&gt;&lt;span style="color: #007700"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$content&lt;/span&gt;&lt;span style="color: #007700"&gt;);
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$content&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;=&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;eregi_replace&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'\_(.[^_]+)\_'&lt;/span&gt;&lt;span style="color: #007700"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'&amp;lt;i&amp;gt;\\1&amp;lt;/i&amp;gt;'&lt;/span&gt;&lt;span style="color: #007700"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$content&lt;/span&gt;&lt;span style="color: #007700"&gt;);

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #FF9900"&gt;//now&amp;nbsp;the&amp;nbsp;variable&amp;nbsp;$content&amp;nbsp;contains&amp;nbsp;HTML&amp;nbsp;formatted&amp;nbsp;text
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//display&amp;nbsp;it
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;echo&amp;nbsp;&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'&amp;lt;hr&amp;nbsp;/&amp;gt;'&lt;/span&gt;&lt;span style="color: #007700"&gt;;

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;echo&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$content&lt;/span&gt;&lt;span style="color: #007700"&gt;;
&lt;br /&gt;}
&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;?&amp;gt;&lt;/span&gt;
&lt;/span&gt;
&lt;/code&gt;
&lt;p&gt;If we try to implement this using string functions it will take quite a lot 
  more lines of extra coding but I leave that to you.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Previous Posts:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/10/basic-custom-tags-parsing-script.html"&gt;Basic 
      &amp;#8220;Custom Tags&amp;#8221; Parsing Script&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/09/simple-file-uploading-script-in-php.html"&gt;Simple 
      File Uploading Script in PHP &lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/08/creating-simple-countdown-timer-using_14.html"&gt;Creating 
      a Simple Countdown Timer Using JavaScript II&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/08/creating-simple-countdown-timer-using.html"&gt;Creating 
      a Simple Countdown Timer Using JavaScript &lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/08/evaluatingexecuting-php-code-at-run.html"&gt;Evaluating/Executing 
      PHP Code at Run-Time Using eval() Function&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/33629562-8709564340756548369?l=learning-computer-programming.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TiGWE/~4/R8yqskBFwTM" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://learning-computer-programming.blogspot.com/feeds/8709564340756548369/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://learning-computer-programming.blogspot.com/2008/11/custom-tags-parsing-using-regular.html#comment-form" title="15 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/33629562/posts/default/8709564340756548369?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/33629562/posts/default/8709564340756548369?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/TiGWE/~3/R8yqskBFwTM/custom-tags-parsing-using-regular.html" title="Custom Tags Parsing Using Regular Expressions" /><author><name>Arvind Gupta</name><uri>http://www.blogger.com/profile/17199066124402939022</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="23" height="32" src="http://one.arvind.googlepages.com/arvind_gupta_photo.jpg" /></author><thr:total>15</thr:total><feedburner:origLink>http://learning-computer-programming.blogspot.com/2008/11/custom-tags-parsing-using-regular.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkYFQXc_cSp7ImA9WxRXGU4.&quot;"><id>tag:blogger.com,1999:blog-33629562.post-2127736140954848145</id><published>2008-10-25T15:23:00.003+05:30</published><updated>2008-10-25T15:51:50.949+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-10-25T15:51:50.949+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Web" /><category scheme="http://www.blogger.com/atom/ns#" term="PHP" /><category scheme="http://www.blogger.com/atom/ns#" term="Useful Scripts" /><category scheme="http://www.blogger.com/atom/ns#" term="Tricks" /><category scheme="http://www.blogger.com/atom/ns#" term="HTML" /><title>Basic "Custom Tags" Parsing Script</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/_x9GMNYdYqcM2HeBhRLsFvYU1ls/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/_x9GMNYdYqcM2HeBhRLsFvYU1ls/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/_x9GMNYdYqcM2HeBhRLsFvYU1ls/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/_x9GMNYdYqcM2HeBhRLsFvYU1ls/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://one.arvind.googlepages.com/parse_custom_atgs.jpg" alt="Basic &amp;#8220;Custom Tags&amp;#8221; Parsing Script" width="240" height="469" align="middle" /&gt;
&lt;p&gt;Today we are going to create a basic Custom Tags parsing script that will parse 
  special symbols (tags) in text for formatting purpose. Just like writing &lt;code&gt;&amp;lt;b&amp;gt;BOLD&amp;lt;/b&amp;gt;&lt;/code&gt;, 
  a web browser parses it as &amp;#8220;BOLD&amp;#8221; in bold letters, same way our 
  script will parse tags created by us. One very popular example of custom tag 
  parsing for formatting purpose is, BBCode which most of the bulletin boards 
  use to let users format their posts.&lt;/p&gt;
&lt;p&gt;This will be a basic example of parsing custom tags so we will only be parsing 
  two tags. One will convert the enclosing text into bold and other will be used 
  for italics. After understanding the basic idea, you can easily add more tags 
  according to your needs and can also use it wherever necessary. One of its good 
  use will be in &lt;a href="http://learning-computer-programming.blogspot.com/2008/05/designing-simple-shout-box-script-in.html"&gt;Shout Boxes&lt;/a&gt; that we had designed a few months back.&lt;/p&gt;
&lt;p&gt;Though many would like the use of &lt;em&gt;&lt;a href="http://en.wikipedia.org/wiki/Regular_expression" target="_blank"&gt;Regular 
  Expressions&lt;/a&gt;&lt;/em&gt; for parsing, we will not be using them here. For the sake 
  of simplicity, we will be using only the basic string manipulation functions 
  available in PHP.&lt;/p&gt;
&lt;p&gt;If you look at the code below, you can see an array (2D) holding our custom 
  tags. Here we&amp;#8217;ll be having four information for each tag. Start tag, end 
  tag (both defined by us), HTML start tag and HTML end tag. To make this more 
  clear, let&amp;#8217;s suppose we want to parse the text &amp;#8220;&lt;code&gt;[b]Text[/b]&lt;/code&gt;&amp;#8221; 
  so that it&amp;#8217;s displayed as &amp;#8220;Text&amp;#8221; in bold. Our start (custom) 
  tag will be &lt;code&gt;[b]&lt;/code&gt;, end tag will be&lt;code&gt; [/b]&lt;/code&gt;, HTML start 
  tag will be &lt;code&gt;&amp;lt;b&amp;gt;&lt;/code&gt; and HTML end tag will be&lt;code&gt; &amp;lt;/b&amp;gt;&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;As we will be parsing two different custom tags, we have eight elements in 
  the array. If you want to add more tags, add four elements for each tag, just 
  like the way the others are. No need to change anything else.&lt;/p&gt;
&lt;p&gt;The code:&lt;/p&gt;
&lt;code&gt;&lt;span style="color: #000000"&gt;
&amp;lt;form&amp;nbsp;name="form1"&amp;nbsp;method="get"&amp;nbsp;action=""&amp;gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;p&amp;gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;!--&amp;nbsp;textarea&amp;nbsp;should&amp;nbsp;display&amp;nbsp;previously&amp;nbsp;wriiten&amp;nbsp;text&amp;nbsp;--&amp;gt;

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;textarea&amp;nbsp;name="content"&amp;nbsp;cols="35"&amp;nbsp;rows="12"&amp;nbsp;id="content"&amp;gt;&lt;span style="color: #0000BB"&gt;&amp;lt;?&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;&lt;br /&gt;if&amp;nbsp;(isset(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$_GET&lt;/span&gt;&lt;span style="color: #007700"&gt;[&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'content'&lt;/span&gt;&lt;span style="color: #007700"&gt;]))&amp;nbsp;echo&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$_GET&lt;/span&gt;&lt;span style="color: #007700"&gt;[&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'content'&lt;/span&gt;&lt;span style="color: #007700"&gt;];&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;?&amp;gt;&lt;/span&gt;&amp;lt;/textarea&amp;gt;

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;/p&amp;gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;p&amp;gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;input&amp;nbsp;name="parse"&amp;nbsp;type="submit"&amp;nbsp;id="parse"&amp;nbsp;value="Parse"&amp;gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;/p&amp;gt;
&lt;br /&gt;&amp;lt;/form&amp;gt;
&lt;br /&gt;&lt;span style="color: #0000BB"&gt;&amp;lt;?
&lt;br /&gt;
&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #007700"&gt;if(isset(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$_GET&lt;/span&gt;&lt;span style="color: #007700"&gt;[&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'parse'&lt;/span&gt;&lt;span style="color: #007700"&gt;]))

&lt;br /&gt;{
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$content&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;=&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$_GET&lt;/span&gt;&lt;span style="color: #007700"&gt;[&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'content'&lt;/span&gt;&lt;span style="color: #007700"&gt;];
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #FF9900"&gt;//convert&amp;nbsp;newlines&amp;nbsp;in&amp;nbsp;the&amp;nbsp;text&amp;nbsp;to&amp;nbsp;HTML&amp;nbsp;"&amp;lt;br&amp;nbsp;/&amp;gt;"

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//required&amp;nbsp;to&amp;nbsp;keep&amp;nbsp;formatting&amp;nbsp;(newlines)
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$content&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;=&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;nl2br&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$content&lt;/span&gt;&lt;span style="color: #007700"&gt;);
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #FF9900"&gt;/*&amp;nbsp;CUSTOM&amp;nbsp;TAGS
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-----------
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;*/

&lt;br /&gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//For&amp;nbsp;Tag&amp;nbsp;1
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$tag&lt;/span&gt;&lt;span style="color: #007700"&gt;[&lt;/span&gt;&lt;span style="color: #0000BB"&gt;0&lt;/span&gt;&lt;span style="color: #007700"&gt;][&lt;/span&gt;&lt;span style="color: #0000BB"&gt;0&lt;/span&gt;&lt;span style="color: #007700"&gt;]&amp;nbsp;=&amp;nbsp;&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'[b]'&lt;/span&gt;&lt;span style="color: #007700"&gt;;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$tag&lt;/span&gt;&lt;span style="color: #007700"&gt;[&lt;/span&gt;&lt;span style="color: #0000BB"&gt;0&lt;/span&gt;&lt;span style="color: #007700"&gt;][&lt;/span&gt;&lt;span style="color: #0000BB"&gt;1&lt;/span&gt;&lt;span style="color: #007700"&gt;]&amp;nbsp;=&amp;nbsp;&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'[/b]'&lt;/span&gt;&lt;span style="color: #007700"&gt;;

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$tag&lt;/span&gt;&lt;span style="color: #007700"&gt;[&lt;/span&gt;&lt;span style="color: #0000BB"&gt;0&lt;/span&gt;&lt;span style="color: #007700"&gt;][&lt;/span&gt;&lt;span style="color: #0000BB"&gt;2&lt;/span&gt;&lt;span style="color: #007700"&gt;]&amp;nbsp;=&amp;nbsp;&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'&amp;lt;strong&amp;gt;'&lt;/span&gt;&lt;span style="color: #007700"&gt;;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$tag&lt;/span&gt;&lt;span style="color: #007700"&gt;[&lt;/span&gt;&lt;span style="color: #0000BB"&gt;0&lt;/span&gt;&lt;span style="color: #007700"&gt;][&lt;/span&gt;&lt;span style="color: #0000BB"&gt;3&lt;/span&gt;&lt;span style="color: #007700"&gt;]&amp;nbsp;=&amp;nbsp;&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'&amp;lt;/strong&amp;gt;'&lt;/span&gt;&lt;span style="color: #007700"&gt;;

&lt;br /&gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #FF9900"&gt;//For&amp;nbsp;Tag&amp;nbsp;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$tag&lt;/span&gt;&lt;span style="color: #007700"&gt;[&lt;/span&gt;&lt;span style="color: #0000BB"&gt;1&lt;/span&gt;&lt;span style="color: #007700"&gt;][&lt;/span&gt;&lt;span style="color: #0000BB"&gt;0&lt;/span&gt;&lt;span style="color: #007700"&gt;]&amp;nbsp;=&amp;nbsp;&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'[i]'&lt;/span&gt;&lt;span style="color: #007700"&gt;;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$tag&lt;/span&gt;&lt;span style="color: #007700"&gt;[&lt;/span&gt;&lt;span style="color: #0000BB"&gt;1&lt;/span&gt;&lt;span style="color: #007700"&gt;][&lt;/span&gt;&lt;span style="color: #0000BB"&gt;1&lt;/span&gt;&lt;span style="color: #007700"&gt;]&amp;nbsp;=&amp;nbsp;&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'[/i]'&lt;/span&gt;&lt;span style="color: #007700"&gt;;

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$tag&lt;/span&gt;&lt;span style="color: #007700"&gt;[&lt;/span&gt;&lt;span style="color: #0000BB"&gt;1&lt;/span&gt;&lt;span style="color: #007700"&gt;][&lt;/span&gt;&lt;span style="color: #0000BB"&gt;2&lt;/span&gt;&lt;span style="color: #007700"&gt;]&amp;nbsp;=&amp;nbsp;&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'&amp;lt;i&amp;gt;'&lt;/span&gt;&lt;span style="color: #007700"&gt;;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$tag&lt;/span&gt;&lt;span style="color: #007700"&gt;[&lt;/span&gt;&lt;span style="color: #0000BB"&gt;1&lt;/span&gt;&lt;span style="color: #007700"&gt;][&lt;/span&gt;&lt;span style="color: #0000BB"&gt;3&lt;/span&gt;&lt;span style="color: #007700"&gt;]&amp;nbsp;=&amp;nbsp;&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'&amp;lt;/i&amp;gt;'&lt;/span&gt;&lt;span style="color: #007700"&gt;;

&lt;br /&gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #FF9900"&gt;//count&amp;nbsp;total&amp;nbsp;no.&amp;nbsp;of&amp;nbsp;tags&amp;nbsp;to&amp;nbsp;parse
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$total_tags&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;=&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;count&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$tag&lt;/span&gt;&lt;span style="color: #007700"&gt;);&amp;nbsp;&lt;/span&gt;&lt;span style="color: #FF9900"&gt;//2&amp;nbsp;for&amp;nbsp;now

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//parse&amp;nbsp;our&amp;nbsp;custom&amp;nbsp;tags&amp;nbsp;adding&amp;nbsp;HTML&amp;nbsp;tags&amp;nbsp;instead
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//which&amp;nbsp;a&amp;nbsp;browser&amp;nbsp;can&amp;nbsp;understand
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;for(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$i&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;=&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;0&lt;/span&gt;&lt;span style="color: #007700"&gt;;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$i&lt;/span&gt;&lt;span style="color: #007700"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$total_tags&lt;/span&gt;&lt;span style="color: #007700"&gt;;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$i&lt;/span&gt;&lt;span style="color: #007700"&gt;++)

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$content&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;=&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;str_replace&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$tag&lt;/span&gt;&lt;span style="color: #007700"&gt;[&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$i&lt;/span&gt;&lt;span style="color: #007700"&gt;][&lt;/span&gt;&lt;span style="color: #0000BB"&gt;0&lt;/span&gt;&lt;span style="color: #007700"&gt;],&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$tag&lt;/span&gt;&lt;span style="color: #007700"&gt;[&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$i&lt;/span&gt;&lt;span style="color: #007700"&gt;][&lt;/span&gt;&lt;span style="color: #0000BB"&gt;2&lt;/span&gt;&lt;span style="color: #007700"&gt;],&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$content&lt;/span&gt;&lt;span style="color: #007700"&gt;);

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$content&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;=&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;str_replace&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$tag&lt;/span&gt;&lt;span style="color: #007700"&gt;[&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$i&lt;/span&gt;&lt;span style="color: #007700"&gt;][&lt;/span&gt;&lt;span style="color: #0000BB"&gt;1&lt;/span&gt;&lt;span style="color: #007700"&gt;],&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$tag&lt;/span&gt;&lt;span style="color: #007700"&gt;[&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$i&lt;/span&gt;&lt;span style="color: #007700"&gt;][&lt;/span&gt;&lt;span style="color: #0000BB"&gt;3&lt;/span&gt;&lt;span style="color: #007700"&gt;],&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$content&lt;/span&gt;&lt;span style="color: #007700"&gt;);

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #FF9900"&gt;//now&amp;nbsp;the&amp;nbsp;variable&amp;nbsp;$content&amp;nbsp;contains&amp;nbsp;HTML&amp;nbsp;formatted&amp;nbsp;text
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//display&amp;nbsp;it
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;echo&amp;nbsp;&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'&amp;lt;hr&amp;nbsp;/&amp;gt;'&lt;/span&gt;&lt;span style="color: #007700"&gt;;

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;echo&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$content&lt;/span&gt;&lt;span style="color: #007700"&gt;;
&lt;br /&gt;}
&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;?&amp;gt;&lt;/span&gt;
&lt;/span&gt;
&lt;/code&gt;
&lt;p&gt; The code is pretty straightforward. Isn&amp;#8217;t it!&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Previous Posts:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/09/simple-file-uploading-script-in-php.html"&gt;Simple 
      File Uploading Script in PHP &lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/08/creating-simple-countdown-timer-using_14.html"&gt;Creating 
      a Simple Countdown Timer Using JavaScript II&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/08/creating-simple-countdown-timer-using.html"&gt;Creating 
      a Simple Countdown Timer Using JavaScript &lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/08/evaluatingexecuting-php-code-at-run.html"&gt;Evaluating/Executing 
      PHP Code at Run-Time Using eval() Function&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/08/blogger-changing-templates-without.html"&gt;Blogger: 
      Changing Templates without Loosing Widget&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/33629562-2127736140954848145?l=learning-computer-programming.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TiGWE/~4/shUsj32cyvs" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://learning-computer-programming.blogspot.com/feeds/2127736140954848145/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://learning-computer-programming.blogspot.com/2008/10/basic-custom-tags-parsing-script.html#comment-form" title="5 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/33629562/posts/default/2127736140954848145?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/33629562/posts/default/2127736140954848145?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/TiGWE/~3/shUsj32cyvs/basic-custom-tags-parsing-script.html" title="Basic &quot;Custom Tags&quot; Parsing Script" /><author><name>Arvind Gupta</name><uri>http://www.blogger.com/profile/17199066124402939022</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="23" height="32" src="http://one.arvind.googlepages.com/arvind_gupta_photo.jpg" /></author><thr:total>5</thr:total><feedburner:origLink>http://learning-computer-programming.blogspot.com/2008/10/basic-custom-tags-parsing-script.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A0MFQ349cSp7ImA9WxRSF0w.&quot;"><id>tag:blogger.com,1999:blog-33629562.post-7342091838909299273</id><published>2008-09-18T11:57:00.000+05:30</published><updated>2008-09-18T12:00:12.069+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-09-18T12:00:12.069+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Web" /><category scheme="http://www.blogger.com/atom/ns#" term="PHP" /><category scheme="http://www.blogger.com/atom/ns#" term="Methods" /><category scheme="http://www.blogger.com/atom/ns#" term="Useful Scripts" /><category scheme="http://www.blogger.com/atom/ns#" term="HTML" /><category scheme="http://www.blogger.com/atom/ns#" term="Files" /><title>Simple File Uploading Script in PHP</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/KbbWz2fcOQWbiTbpjN9TqnBhuzk/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/KbbWz2fcOQWbiTbpjN9TqnBhuzk/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/KbbWz2fcOQWbiTbpjN9TqnBhuzk/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/KbbWz2fcOQWbiTbpjN9TqnBhuzk/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p align="center"&gt;&lt;img src="http://one.arvind.googlepages.com/file_upload.gif" alt="Simple File Uploading Script in PHP " width="282" height="211" /&gt;&lt;/p&gt;
&lt;p&gt;PHP is undoubtedly the best programming language when it comes to web programming. 
  It gives us so many features and capabilities, a few of which we&amp;#8217;ve discussed 
  already. So continuing with that, today we&amp;#8217;ll see how we can use a few 
  lines of code to create a script that&amp;#8217;d allow file uploading right from 
  the web browser. File upload feature is definitely useful kinds of website but 
  at the same time very much vulnerable to malicious attacks as well. So use it 
  with a LOT of precautions!&lt;/p&gt;
&lt;p&gt;For this example, we&amp;#8217;ll need a front-end web page that&amp;#8217;ll accept 
  the file from the user and a backend script to process and store the file. Let&amp;#8217;s 
  look at the codes of each:&lt;/p&gt;
&lt;p&gt;&lt;font size="4"&gt;upload.html:&lt;/font&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&lt;font color="#000000"&gt;
  &amp;lt;html&amp;gt;
  &amp;lt;body&amp;gt;
  &amp;lt;form action=&lt;font color="#408080"&gt;&amp;quot;upload_file.php&amp;quot;&lt;/font&gt; method=&lt;font color="#408080"&gt;&amp;quot;post&amp;quot;&lt;/font&gt;
  enctype=&lt;font color="#408080"&gt;&amp;quot;multipart/form-data&amp;quot;&lt;/font&gt;&amp;gt;
  &amp;lt;label &lt;font color="#0000ff"&gt;for&lt;/font&gt;=&lt;font color="#408080"&gt;&amp;quot;file&amp;quot;&lt;/font&gt;&amp;gt;Filename:&amp;lt;/label&amp;gt;
  &amp;lt;input type=&lt;font color="#408080"&gt;&amp;quot;file&amp;quot;&lt;/font&gt; name=&lt;font color="#408080"&gt;&amp;quot;file&amp;quot;&lt;/font&gt; id=&lt;font color="#408080"&gt;&amp;quot;file&amp;quot;&lt;/font&gt; /&amp;gt;
  &amp;lt;br /&amp;gt;
  &amp;lt;input type=&lt;font color="#408080"&gt;&amp;quot;submit&amp;quot;&lt;/font&gt; name=&lt;font color="#408080"&gt;&amp;quot;submit&amp;quot;&lt;/font&gt; value=&lt;font color="#408080"&gt;&amp;quot;Submit&amp;quot;&lt;/font&gt; /&amp;gt;
  &amp;lt;/form&amp;gt;
  &amp;lt;/body&amp;gt;
  &amp;lt;/html&amp;gt;
&lt;/font&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt; Here we have a HTML form that calls the script on submission. The method of 
  data sending should be &amp;#8220;&lt;code&gt;POST&lt;/code&gt;&amp;#8221; and there should be and 
  enctype as &amp;#8220;&lt;code&gt;multipart/form-data&lt;/code&gt;&amp;#8221; which means we can 
  upload binary form data. The input type &amp;#8220;file&amp;#8221; opens the File Input 
  Box that&amp;#8217;d let the user browse for the file. The submit button &amp;#8220;Upload&amp;#8221; 
  submits the form as usual.&lt;/p&gt;
&lt;p&gt;&lt;font size="4"&gt;upload_file.php:&lt;/font&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&lt;span style="color: #000000"&gt;&lt;span style="color: #0000BB"&gt;&amp;lt;?php 
&lt;/span&gt;&lt;span style="color: #007700"&gt;if&amp;nbsp;(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$_FILES&lt;/span&gt;&lt;span style="color: #007700"&gt;[&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"file"&lt;/span&gt;&lt;span style="color: #007700"&gt;][&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"error"&lt;/span&gt;&lt;span style="color: #007700"&gt;]&amp;nbsp;&amp;gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;0&lt;/span&gt;&lt;span style="color: #007700"&gt;) 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;echo&amp;nbsp;&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"Error::&amp;nbsp;"&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;.&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$_FILES&lt;/span&gt;&lt;span style="color: #007700"&gt;[&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"file"&lt;/span&gt;&lt;span style="color: #007700"&gt;][&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"error"&lt;/span&gt;&lt;span style="color: #007700"&gt;]&amp;nbsp;.&amp;nbsp;&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"&amp;lt;br&amp;nbsp;/&amp;gt;"&lt;/span&gt;&lt;span style="color: #007700"&gt;; 
else 
{ 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;file_exists&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$_FILES&lt;/span&gt;&lt;span style="color: #007700"&gt;[&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"file"&lt;/span&gt;&lt;span style="color: #007700"&gt;][&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"name"&lt;/span&gt;&lt;span style="color: #007700"&gt;])) 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{ 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;echo&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$_FILES&lt;/span&gt;&lt;span style="color: #007700"&gt;[&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"file"&lt;/span&gt;&lt;span style="color: #007700"&gt;][&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"name"&lt;/span&gt;&lt;span style="color: #007700"&gt;]&amp;nbsp;.&amp;nbsp;&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"&amp;nbsp;already&amp;nbsp;exists.&amp;nbsp;"&lt;/span&gt;&lt;span style="color: #007700"&gt;; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;} 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{ 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;move_uploaded_file&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$_FILES&lt;/span&gt;&lt;span style="color: #007700"&gt;[&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"file"&lt;/span&gt;&lt;span style="color: #007700"&gt;][&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"tmp_name"&lt;/span&gt;&lt;span style="color: #007700"&gt;],&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$_FILES&lt;/span&gt;&lt;span style="color: #007700"&gt;[&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"file"&lt;/span&gt;&lt;span style="color: #007700"&gt;][&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"name"&lt;/span&gt;&lt;span style="color: #007700"&gt;]); 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;echo&amp;nbsp;&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"File&amp;nbsp;&amp;lt;b&amp;gt;"&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;.&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$_FILES&lt;/span&gt;&lt;span style="color: #007700"&gt;[&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"file"&lt;/span&gt;&lt;span style="color: #007700"&gt;][&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"name"&lt;/span&gt;&lt;span style="color: #007700"&gt;]&amp;nbsp;.&amp;nbsp;&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"&amp;lt;/b&amp;gt;&amp;nbsp;uploaded&amp;nbsp;successfully!"&lt;/span&gt;&lt;span style="color: #007700"&gt;; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;} 
} 
&lt;/span&gt;&lt;span style="color: #0000BB"&gt;?&amp;gt;&lt;/span&gt; &lt;/span&gt; &lt;/code&gt; &lt;/pre&gt;
&lt;p&gt;Just like we had POST form data in &lt;code&gt;$_POST[]&lt;/code&gt; and GET data in &lt;code&gt;$_GET[]&lt;/code&gt; 
  array same way to have files sent to script we use &lt;code&gt;$_FILES[]&lt;/code&gt; array.&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;&lt;code&gt;$_FILES[&amp;quot;file&amp;quot;][&amp;quot;error&amp;quot;]&lt;/code&gt;: &lt;/strong&gt;Tells 
      us if there is any error in uploading. Note that &amp;#8220;file&amp;#8221; the 
      first string index of the array is the name of the &amp;#8220;File&amp;#8221; input 
      type from the HTML form.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;&lt;code&gt;$_FILES[&amp;quot;file&amp;quot;][&amp;quot;tmp_name&amp;quot;]:&lt;/code&gt;&lt;/strong&gt; 
      All the files sent to any script is stores in a temporary directory by PHP, 
      this tells us the location of that temporary file.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;&lt;code&gt;$_FILES[&amp;quot;file&amp;quot;][&amp;quot;name&amp;quot;]:&lt;/code&gt;&lt;/strong&gt; 
      It tells us the name of the file on the users&amp;#8217; computer.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;&lt;code&gt;move_uploaded_file():&lt;/code&gt;&lt;/strong&gt; As files sent to scripts 
      are just stored temporarily, we have to save it to some place, for this 
      we use this PHP function. It&amp;#8217;s first parameter is the temporary file 
      location and second is the place we need to store the file and with what 
      name. We are storing it to the same directory the script is in and with 
      name same as on the users&amp;#8217; computer.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;NOTE: This is just meant for example purpose and you shouldn&amp;#8217;t have this 
  on your server as it is an open invitation to hackers/spammers. If you need 
  upload facility on your website in all the cases you should have some kind of 
  &lt;em&gt; &lt;a href="http://learning-computer-programming.blogspot.com/2008/05/implementing-user-authorization-using.html"&gt;authentication 
  system&lt;/a&gt;&lt;/em&gt; that'd only allow registered users to upload anything. you should 
  also accept only certain file types. you wouldn't like someone uploading/running 
  spamming script off your server. Would you? there may be a few other precautions 
  that you may need to take depending on the purpose you intend to use the script 
  for. &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Previous Posts:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/08/creating-simple-countdown-timer-using_14.html"&gt;Creating 
      a Simple Countdown Timer Using JavaScript II&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/08/creating-simple-countdown-timer-using.html"&gt;Creating 
      a Simple Countdown Timer Using JavaScript &lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/08/evaluatingexecuting-php-code-at-run.html"&gt;Evaluating/Executing 
      PHP Code at Run-Time Using eval() Function&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/08/blogger-changing-templates-without.html"&gt;Blogger: 
      Changing Templates without Loosing Widget&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/33629562-7342091838909299273?l=learning-computer-programming.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TiGWE/~4/j1YLnnW5eeA" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://learning-computer-programming.blogspot.com/feeds/7342091838909299273/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://learning-computer-programming.blogspot.com/2008/09/simple-file-uploading-script-in-php.html#comment-form" title="11 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/33629562/posts/default/7342091838909299273?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/33629562/posts/default/7342091838909299273?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/TiGWE/~3/j1YLnnW5eeA/simple-file-uploading-script-in-php.html" title="Simple File Uploading Script in PHP" /><author><name>Arvind Gupta</name><uri>http://www.blogger.com/profile/17199066124402939022</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="23" height="32" src="http://one.arvind.googlepages.com/arvind_gupta_photo.jpg" /></author><thr:total>11</thr:total><feedburner:origLink>http://learning-computer-programming.blogspot.com/2008/09/simple-file-uploading-script-in-php.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0MBQHw5fSp7ImA9WxRSFUs.&quot;"><id>tag:blogger.com,1999:blog-33629562.post-1077131267278643157</id><published>2008-09-16T15:27:00.002+05:30</published><updated>2008-09-16T16:07:31.225+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-09-16T16:07:31.225+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Web" /><category scheme="http://www.blogger.com/atom/ns#" term="Personal" /><title>Finally a Blogging Platform for the Mobile Web (WAP)</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/b72JBnTM3ceC3tbHNI0NTtnVcdQ/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/b72JBnTM3ceC3tbHNI0NTtnVcdQ/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/b72JBnTM3ceC3tbHNI0NTtnVcdQ/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/b72JBnTM3ceC3tbHNI0NTtnVcdQ/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Most of the time I browse internet for reading blogs, checking emails etc. 
  I do it on my cell phone. One day I thought why not create a mobile website 
  or better yet blog, and started searching around. What did I find? Well, nothing 
  much useful. In this big world and yet bigger web, to my disappointment, I couldn&amp;#8217;t 
  find any website offering free blogs like we do on the normal (desktop) web. 
  Moreover, those that offered mobile websites, I just didn&amp;#8217;t like their 
  service. You just have to spend so much time to just have a single page up!&lt;/p&gt;
&lt;p&gt;What I had in my mind was a service that&amp;#8217;d offer free blogs, let me register 
  it from the mobile phone, let me post from the mobile phone, in other words 
  a service that&amp;#8217;d let me operate the whole thing right from the mobile 
  phone itself. Days passed and then, rather than me wanting these services I 
  thought of offering them to others instead, of course for FREE. Therefore I 
  took a nearly a month off and created what I wanted myself. Here it is &lt;a href="http://www.mywapblog.com/"&gt;MyWapBlog.com&lt;/a&gt; 
  &lt;em&gt;&lt;strong&gt;(You need a mobile phone to access it. Not accessible form desktop 
  browsers except Opera, and FireFox with &lt;a href="https://addons.mozilla.org/firefox/addon/1345" rel="nofollow"&gt;addon&lt;/a&gt;)&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;A picture is worth a thousand words, here area a few of them:
&lt;/p&gt;
&lt;p align="center"&gt;&lt;img src="http://one.arvind.googlepages.com/mywapblog_01.JPG" alt="MyWapBlog.com - Homepage" width="255" height="347" /&gt;&lt;br /&gt;
  MyWapBlog.com Homepage&lt;/p&gt;
&lt;p align="center"&gt;&lt;img src="http://one.arvind.googlepages.com/mywapblog_02.JPG" alt="MyWapBlog.com - Registration Page" width="256" height="348" /&gt;&lt;br /&gt;
  Registration Page - You'll get your blog at &lt;strong&gt;your-name.mywapblog.com&lt;/strong&gt;&lt;/p&gt;
&lt;p align="center"&gt;&lt;strong&gt;&lt;img src="http://one.arvind.googlepages.com/mywapblog_03.JPG" alt="MyWapBlog.com - Dashboard" width="256" height="348" /&gt;&lt;br /&gt;
  &lt;/strong&gt;After registration/logging in you'll see your dashboard like shown 
  above&lt;/p&gt;
&lt;p align="center"&gt;&lt;img src="http://one.arvind.googlepages.com/mywapblog_05.JPG" alt="MyWapBlog.com - User Blog" width="257" height="343" /&gt;&lt;br /&gt;
  Your blog looks like this using the &amp;quot;Default-2&amp;quot; theme&lt;/p&gt;
&lt;p align="center"&gt;&lt;img src="http://one.arvind.googlepages.com/mywapblog_04.JPG" alt="MyWapBlog.com - Blog Theme Choice" width="255" height="347" /&gt;&lt;br /&gt;
  You can choose between the three themes available now for your blog's layout. 
  More themes will be added soon.&lt;/p&gt;
&lt;p align="left"&gt;While I&amp;#8217;ve sorted most of the bugs that I could find in 
  ten-days testing period, there might (sure) still be quite a few of them. Therefore, 
  the only thing I&amp;#8217;d like to ask for is to use the Feedback Form (on Dashboard 
  Page) a lot!&lt;/p&gt;
&lt;p align="left"&gt;Thanks a lot for reading! Go get your &lt;a href="http://www.mywapblog.com"&gt;Free 
  Wap Blog&lt;/a&gt; Now!&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/33629562-1077131267278643157?l=learning-computer-programming.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TiGWE/~4/ajHj3M-gdVE" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://learning-computer-programming.blogspot.com/feeds/1077131267278643157/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://learning-computer-programming.blogspot.com/2008/09/finally-blogging-platform-for-mobile.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/33629562/posts/default/1077131267278643157?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/33629562/posts/default/1077131267278643157?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/TiGWE/~3/ajHj3M-gdVE/finally-blogging-platform-for-mobile.html" title="Finally a Blogging Platform for the Mobile Web (WAP)" /><author><name>Arvind Gupta</name><uri>http://www.blogger.com/profile/17199066124402939022</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="23" height="32" src="http://one.arvind.googlepages.com/arvind_gupta_photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://learning-computer-programming.blogspot.com/2008/09/finally-blogging-platform-for-mobile.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkEHR3g9eyp7ImA9WxRTFUw.&quot;"><id>tag:blogger.com,1999:blog-33629562.post-8029162815792909948</id><published>2008-09-04T12:12:00.000+05:30</published><updated>2008-09-04T12:13:56.663+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-09-04T12:13:56.663+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="HTML" /><title>Designing a Simple HTML Code &amp; Preview Tool (Online)</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/t2t5n6pG93SzChSOdAQ9z1izsIE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/t2t5n6pG93SzChSOdAQ9z1izsIE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/t2t5n6pG93SzChSOdAQ9z1izsIE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/t2t5n6pG93SzChSOdAQ9z1izsIE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p align="center"&gt;&lt;img src="http://one.arvind.googlepages.com/code_preview01.gif" alt="Designing a Simple HTML Code &amp;amp; Preview Tool (Online)" width="259" height="217"&gt;&lt;/p&gt;
&lt;p&gt;With online CMSs everywhere and craze of blogging like never before, we see 
  some sort of online HTML editors everywhere. Ever blogged or posted in some 
  forum? Most of them have it! These editors let you write, format, preview and 
  tinker with the HTML code before publishing anything. Most of them have a nice 
  UI to format everything much like the desktop applications like &lt;em&gt;NVu, Dreamweaver 
  &lt;/em&gt;etc. these online editors also let you manually change or write HTML code 
  that can be previewed without leaving the page. &lt;/p&gt;
&lt;p&gt;Well what we are going to design today is a scaled down version (say simple) 
  of these kinds of editors. It&amp;#8217;d let you write (or paste) HTML code and 
  preview how it&amp;#8217;d look. What it wouldn&amp;#8217;t let you do is to format 
  or change anything while in the preview mode. We will be using HTML, JavaScript 
  and a little inline CSS.&lt;/p&gt;
&lt;p&gt;&lt;font size="4"&gt;Basic Theory&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;If you look at the HTML editors used by Blogger and Wordpress, they have two 
  modes, Code and Compose. In code mode HTML code is displayed which can also 
  be edited. On the other hand in compose mode, preview of the code is displayed 
  which can be edited/formatted using its GUI. Interesting thing here is that 
  both the mode displays in the same place, giving a feeling that the same code 
  box is changing to the Compose box.&lt;/p&gt;
&lt;p&gt;For our purpose, we can use a HTML textarea for code view and an iframe for 
  preview. Iframe is the simplest way of showing HTML preview that could also 
  be made to work in edit mode, therefore letting us format things using the UI 
  and see the code in code view.&lt;/p&gt;
&lt;p&gt;&lt;font size="4"&gt;Working&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;From the staring both the textarea and the iframe are placed in the page. Textarea 
  is be styled to be visible (&lt;code&gt;display: block;&lt;/code&gt;) and the iframe to 
  be invisible (&lt;code&gt;display:none;&lt;/code&gt;). When you type in some code in the 
  code view (textarea) and switch to preview mode, a JavaScript function is called 
  that makes the textarea invisible an the iframe visible. It also places the 
  code (form the textarea) as HTML for the iframe, which in turn displays the 
  code as it&amp;#8217;d in a browser. Again when you switch back to code view, textarea 
  is made visible again and the iframe invisible. If we give both the textarea 
  and iframe the same look, it&amp;#8217;d give the feeling that the same box is being 
  used to show code as well as preview.&lt;/p&gt;
&lt;p&gt;The button&amp;#8217;s value is also changed to reflect which mode we are in and 
  clicking it would result in which view.&lt;/p&gt;
&lt;p&gt;&lt;font size="4"&gt;Code&lt;/font&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&lt;font color="#000000"&gt;
  &amp;lt;html&amp;gt;
  &amp;lt;head&amp;gt;
  &amp;lt;title&amp;gt;Code &amp;amp; Preview&amp;lt;/title&amp;gt;


  &amp;lt;script language=&lt;font color="#408080"&gt;&amp;quot;JavaScript&amp;quot;&lt;/font&gt; type=&lt;font color="#408080"&gt;&amp;quot;text/JavaScript&amp;quot;&lt;/font&gt;&amp;gt;
  &lt;font color="#008000"&gt;//flag to store current state of view (code or preview)&lt;/font&gt;
  &lt;font color="#0000ff"&gt;var&lt;/font&gt; flag=&lt;font color="#ff0000"&gt;1&lt;/font&gt;;

  &lt;font color="#008000"&gt;//var to store code forom the textarea&lt;/font&gt;
  &lt;font color="#0000ff"&gt;var&lt;/font&gt; val1=&lt;font color="#408080"&gt;''&lt;/font&gt;;

  &lt;font color="#0000ff"&gt;function&lt;/font&gt; changeMode()
  {
    &lt;font color="#008000"&gt;//store code from the textarea&lt;/font&gt;
    val1=document.form1.code.value;

    &lt;font color="#008000"&gt;//check which view we are in&lt;/font&gt;
    &lt;font color="#0000ff"&gt;if&lt;/font&gt; (flag==&lt;font color="#ff0000"&gt;1&lt;/font&gt;)&lt;font color="#008000"&gt;//code view&lt;/font&gt;
    {
      &lt;font color="#008000"&gt;//set textarea to be invisible&lt;/font&gt;
      &lt;font color="#008000"&gt;//notice how style property is accessed&lt;/font&gt;
      document.getElementById(&lt;font color="#408080"&gt;'code'&lt;/font&gt;).style.display = &lt;font color="#408080"&gt;&amp;quot;none&amp;quot;&lt;/font&gt;;
      document.getElementById(&lt;font color="#408080"&gt;'preview'&lt;/font&gt;).style.display = &lt;font color="#408080"&gt;&amp;quot;block&amp;quot;&lt;/font&gt;;

      &lt;font color="#008000"&gt;//give the iframe the HTML code to display&lt;/font&gt;
      &lt;font color="#008000"&gt;//note how an iframe's properties are accessed&lt;/font&gt;
      &lt;font color="#008000"&gt;//is's because an iframe is a seperate window itself&lt;/font&gt;
      document.getElementById(&lt;font color="#408080"&gt;&amp;quot;preview&amp;quot;&lt;/font&gt;).contentWindow.document.body.innerHTML=val1;

      &lt;font color="#008000"&gt;//rename the button&lt;/font&gt;
      document.getElementById(&lt;font color="#408080"&gt;'submit'&lt;/font&gt;).value = &lt;font color="#408080"&gt;&amp;quot;Code&amp;quot;&lt;/font&gt;;

      flag=&lt;font color="#ff0000"&gt;2&lt;/font&gt;;
    }
    &lt;font color="#0000ff"&gt;else&lt;/font&gt;
    {
      document.getElementById(&lt;font color="#408080"&gt;'preview'&lt;/font&gt;).style.display =&lt;font color="#408080"&gt;&amp;quot;none&amp;quot;&lt;/font&gt;;
      document.getElementById(&lt;font color="#408080"&gt;'code'&lt;/font&gt;).style.display =&lt;font color="#408080"&gt;&amp;quot;block&amp;quot;&lt;/font&gt;;

      document.getElementById(&lt;font color="#408080"&gt;'submit'&lt;/font&gt;).value = &lt;font color="#408080"&gt;&amp;quot;Preview&amp;quot;&lt;/font&gt;;

      flag=&lt;font color="#ff0000"&gt;1&lt;/font&gt;;
    }
  }
  &amp;lt;/script&amp;gt;

  &amp;lt;/head&amp;gt;

  &amp;lt;body&amp;gt;
  &amp;lt;form name=&lt;font color="#408080"&gt;&amp;quot;form1&amp;quot;&lt;/font&gt; method=&lt;font color="#408080"&gt;&amp;quot;post&amp;quot;&lt;/font&gt; action=&lt;font color="#408080"&gt;&amp;quot;&amp;quot;&lt;/font&gt;&amp;gt;
    &amp;lt;p id=&lt;font color="#408080"&gt;&amp;quot;textb&amp;quot;&lt;/font&gt;&amp;gt;
  &amp;lt;iframe style=&lt;font color="#408080"&gt;&amp;quot;display: none&amp;quot;&lt;/font&gt; id=&lt;font color="#408080"&gt;&amp;quot;preview&amp;quot;&lt;/font&gt; width=&lt;font color="#408080"&gt;&amp;quot;600px&amp;quot;&lt;/font&gt; height=&lt;font color="#408080"&gt;&amp;quot;300px&amp;quot;&lt;/font&gt; scrolling=&lt;font color="#408080"&gt;&amp;quot;auto&amp;quot;&lt;/font&gt;&amp;gt;&amp;lt;/iframe&amp;gt;
      &amp;lt;textarea style=&lt;font color="#408080"&gt;&amp;quot;display: block;width:600px; height:300px&amp;quot;&lt;/font&gt; name=&lt;font color="#408080"&gt;&amp;quot;code&amp;quot;&lt;/font&gt; id=&lt;font color="#408080"&gt;&amp;quot;code&amp;quot;&lt;/font&gt;&amp;gt;&amp;lt;/textarea&amp;gt;
    &amp;lt;/p&amp;gt;
    &amp;lt;p&amp;gt;
      &amp;lt;input id=&lt;font color="#408080"&gt;&amp;quot;submit&amp;quot;&lt;/font&gt; type=&lt;font color="#408080"&gt;&amp;quot;button&amp;quot;&lt;/font&gt; name=&lt;font color="#408080"&gt;&amp;quot;Submit&amp;quot;&lt;/font&gt; onClick=&lt;font color="#408080"&gt;&amp;quot;changeMode()&amp;quot;&lt;/font&gt; value=&lt;font color="#408080"&gt;&amp;quot;Preview&amp;quot;&lt;/font&gt;&amp;gt;
    &amp;lt;/p&amp;gt;
  &amp;lt;/form&amp;gt;
  &amp;lt;/body&amp;gt;
  &amp;lt;/html&amp;gt;
&lt;/font&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Previous Posts:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/08/creating-simple-countdown-timer-using_14.html"&gt;Creating 
      a Simple Countdown Timer Using JavaScript II&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/08/creating-simple-countdown-timer-using.html"&gt;Creating 
      a Simple Countdown Timer Using JavaScript &lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/08/evaluatingexecuting-php-code-at-run.html"&gt;Evaluating/Executing 
      PHP Code at Run-Time Using eval() Function&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/08/blogger-changing-templates-without.html"&gt;Blogger: 
      Changing Templates without Loosing Widgets&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/08/how-do-i-color-highlight-php-source.html"&gt;How 
      Do I Color-Highlight PHP Source Codes&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/33629562-8029162815792909948?l=learning-computer-programming.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TiGWE/~4/1sK9FJ9r9Sk" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://learning-computer-programming.blogspot.com/feeds/8029162815792909948/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://learning-computer-programming.blogspot.com/2008/09/designing-simple-html-code-preview-tool.html#comment-form" title="8 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/33629562/posts/default/8029162815792909948?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/33629562/posts/default/8029162815792909948?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/TiGWE/~3/1sK9FJ9r9Sk/designing-simple-html-code-preview-tool.html" title="Designing a Simple HTML Code &amp;amp; Preview Tool (Online)" /><author><name>Arvind Gupta</name><uri>http://www.blogger.com/profile/17199066124402939022</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="23" height="32" src="http://one.arvind.googlepages.com/arvind_gupta_photo.jpg" /></author><thr:total>8</thr:total><feedburner:origLink>http://learning-computer-programming.blogspot.com/2008/09/designing-simple-html-code-preview-tool.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CU4HQn45fyp7ImA9WxdbFkQ.&quot;"><id>tag:blogger.com,1999:blog-33629562.post-5762057284830098140</id><published>2008-08-14T11:24:00.002+05:30</published><updated>2008-08-14T11:35:33.027+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-08-14T11:35:33.027+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript" /><category scheme="http://www.blogger.com/atom/ns#" term="Methods" /><category scheme="http://www.blogger.com/atom/ns#" term="Tricks" /><category scheme="http://www.blogger.com/atom/ns#" term="CSS" /><category scheme="http://www.blogger.com/atom/ns#" term="HTML" /><title>Creating a Simple Countdown Timer Using JavaScript II...Using getElementById() Method</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/hfrdQ8z3eZm0X-jyW6xWvxNGG1s/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/hfrdQ8z3eZm0X-jyW6xWvxNGG1s/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/hfrdQ8z3eZm0X-jyW6xWvxNGG1s/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/hfrdQ8z3eZm0X-jyW6xWvxNGG1s/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p align="center"&gt;&lt;img src="http://one.arvind.googlepages.com/js_count_down_timer02.gif" alt="Using getElementById(id) Method" width="205" height="269"&gt;&lt;/p&gt;
&lt;p&gt;Speaking of yesterday&amp;#8217;s post, it had the following problems: &lt;/p&gt;
&lt;p&gt;&lt;font size="5"&gt;1.&lt;/font&gt; It could not easily be embedded into an existing page.&lt;br&gt;
  &lt;font size="5"&gt;2.&lt;/font&gt; It could not be placed wherever we wanted it to be 
  nor it could be aligned or styled easily.&lt;br&gt;
  &lt;font size="5"&gt;3.&lt;/font&gt; Rather than updating the same number to countdown it 
  showed a series of numbers as countdown proceeded.&lt;/p&gt;
&lt;p&gt;Well all these problems can easily be solved by one of JavaScript&amp;#8217;s powerful 
  method &lt;code&gt;getElementById()&lt;/code&gt;. This is &lt;code&gt;documents&lt;/code&gt;&amp;#8217;s 
  method which can be used to access HTML entities within JavaScript with the 
  help of their IDs (which is unique).&lt;/p&gt;
&lt;p&gt;For example we can access the HTML entity and its values etc. with the ID &lt;code&gt;one&lt;/code&gt; 
  as:&lt;/p&gt;
&lt;code&gt;&lt;font color="#000000"&gt;document.getElementById(&amp;quot;one&amp;quot;)&lt;/font&gt;&lt;/code&gt; 
&lt;p&gt;
  The HTML object may be defined like below:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&amp;lt;p id=&amp;quot;one&amp;quot;&amp;gt;some text&amp;lt;/p&amp;gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;You get!&lt;/p&gt;
&lt;p&gt;OK, how can this be used to solve our problems, let&amp;#8217;s see.&lt;/p&gt;
&lt;p&gt;As we know, the HTML entities such as &lt;code&gt;&amp;lt;p&amp;gt;,&amp;lt;div&amp;gt;, &amp;lt;span&amp;gt;&lt;/code&gt; 
  etc. can be placed anywhere very easily. They can also be styled and aligned 
  perfectly. So if we could print the timer in one of these, it&amp;#8217;d be the 
  most efficient technique. How? Using &lt;code&gt;getElementById().&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;The body of tags such as &lt;code&gt;&amp;lt;p&amp;gt;, &amp;lt;div&amp;gt; or &amp;lt;span&amp;gt;&lt;/code&gt; 
  can be accessed via JavaScript as:&lt;/p&gt;
&lt;code&gt;&lt;font color="#000000"&gt;document.getElementById(&amp;quot;one&amp;quot;).innerHTML&lt;/font&gt;&lt;/code&gt; 
&lt;p&gt;
  e.g.: If we execute the following code:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&lt;font color="#000000"&gt;document.getElementById(&amp;quot;one&amp;quot;).innerHTML=&amp;quot;hello!!&amp;quot;;&lt;/font&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;
  it&amp;#8217;d be same as having the following HTML tag:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&amp;lt;p id=&amp;quot;one&amp;quot;&amp;gt;hello!!&amp;quot;&amp;lt;/p&amp;gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;
  This way two of our problems have been solved. What about the third one? It 
  too has been solved, if you look closely.&lt;/p&gt;
&lt;p&gt;For example when you write:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&lt;font color="#000000"&gt;document.getElementById(&amp;quot;one&amp;quot;).innerHTML=&amp;quot;First&amp;quot;;&lt;/font&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;
  And then:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&lt;font color="#000000"&gt;document.getElementById(&amp;quot;one&amp;quot;).innerHTML=&amp;quot;Second&amp;quot;;&lt;/font&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt; would be displayed as having the text &amp;#8220;Second&amp;#8221;.&lt;/p&gt;
&lt;p&gt;OK, below is the completed code:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&lt;font color="#000000"&gt;
  &amp;lt;!DOCTYPE HTML PUBLIC &lt;font color="#408080"&gt;&amp;quot;-//W3C//DTD HTML 4.01 Transitional//EN&amp;quot;&lt;/font&gt;&amp;gt;
  &amp;lt;html&amp;gt;

  &amp;lt;head&amp;gt;
  &amp;lt;title&amp;gt;JavaScript Countdown Timer&amp;lt;/title&amp;gt;
  &amp;lt;meta http-equiv=&lt;font color="#408080"&gt;&amp;quot;Content-Type&amp;quot;&lt;/font&gt; content=&lt;font color="#408080"&gt;&amp;quot;text/html; charset=iso-8859-1&amp;quot;&lt;/font&gt;&amp;gt;
  &amp;lt;script language=&lt;font color="#408080"&gt;&amp;quot;JavaScript&amp;quot;&lt;/font&gt; type=&lt;font color="#408080"&gt;&amp;quot;text/JavaScript&amp;quot;&lt;/font&gt;&amp;gt;

  &lt;font color="#008000"&gt;//to store timeout ID&lt;/font&gt;
  &lt;font color="#0000ff"&gt;var&lt;/font&gt; tID;
  &lt;font color="#0000ff"&gt;function&lt;/font&gt; tickTimer(t,id)
  {
    &lt;font color="#008000"&gt;//if time is in range&lt;/font&gt;
    &lt;font color="#0000ff"&gt;if&lt;/font&gt;(t&amp;gt;=&lt;font color="#ff0000"&gt;0&lt;/font&gt;)
    {
      document.getElementById(id).innerHTML=t;
      t=t-&lt;font color="#ff0000"&gt;1&lt;/font&gt;;
      tID=setTimeout(&lt;font color="#408080"&gt;&amp;quot;tickTimer('&amp;quot;&lt;/font&gt;+t+&lt;font color="#408080"&gt;&amp;quot;','&amp;quot;&lt;/font&gt;+id+&lt;font color="#408080"&gt;&amp;quot;')&amp;quot;&lt;/font&gt;,&lt;font color="#ff0000"&gt;1000&lt;/font&gt;);
    }
    &lt;font color="#008000"&gt;//stop the timeout event&lt;/font&gt;

    &lt;font color="#0000ff"&gt;else&lt;/font&gt;
    {
      killTimer(tID);
      document.getElementById(id).innerHTML=&lt;font color="#408080"&gt;&amp;quot;Time Out!!&amp;quot;&lt;/font&gt;;
    }
  }

  &lt;font color="#008000"&gt;//function to stop the timeout event&lt;/font&gt;
  &lt;font color="#0000ff"&gt;function&lt;/font&gt; killTimer(id)
  {
    clearTimeout(id);
  }
  &amp;lt;/script&amp;gt;

  &lt;font color="#008000"&gt;&amp;lt;!--style the ID --&amp;gt;&lt;/font&gt;

  &amp;lt;style&amp;gt;
  #timer {
    background: #000;
    color: #fff;
    font-size: &lt;font color="#ff0000"&gt;20px&lt;/font&gt;;
  }
  &amp;lt;/style&amp;gt;
  &amp;lt;/head&amp;gt;
  &lt;font color="#008000"&gt;&amp;lt;!--pass the id to timer has to attached to --&amp;gt;&lt;/font&gt;
  &amp;lt;body onLoad=&lt;font color="#408080"&gt;&amp;quot;tickTimer(9,'timer')&amp;quot;&lt;/font&gt; onUnload=&lt;font color="#408080"&gt;&amp;quot;killTimer(tID)&amp;quot;&lt;/font&gt;&amp;gt;

  &amp;lt;p&amp;gt;Timer: &amp;lt;span id=&lt;font color="#408080"&gt;&amp;quot;timer&amp;quot;&lt;/font&gt;&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt;
  &amp;lt;/body&amp;gt;
  &amp;lt;/html&amp;gt;
&lt;/font&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;It depends on what you intend regarding which tag you should use to place to 
  timer. If you want it to be inline with some text use &lt;code&gt;&amp;lt;span&amp;gt;&lt;/code&gt;. 
  &lt;code&gt;&amp;lt;p&amp;gt; &lt;/code&gt;would make it to be in a different paragraph.&lt;/p&gt;
&lt;p&gt;So in this post we saw a very powerful method &lt;code&gt;getElementById()&lt;/code&gt; 
  which can be used to access HTML objects and manipulate them. Check back for 
  more!&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Previous Posts:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/08/creating-simple-countdown-timer-using.html"&gt;Creating 
      a Simple Countdown Timer Using JavaScript &lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/08/evaluatingexecuting-php-code-at-run.html"&gt;Evaluating/Executing 
      PHP Code at Run-Time Using eval() Function&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/08/blogger-changing-templates-without.html"&gt;Blogger: 
      Changing Templates without Loosing Widgets&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/08/how-do-i-color-highlight-php-source.html"&gt;How 
      Do I Color-Highlight PHP Source Codes&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/08/web-scraping-gathering-related-searches.html"&gt;Web 
      Scraping: Gathering &amp;quot;Related Searches&amp;quot; Keyword Data From Google 
      Search Results&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/33629562-5762057284830098140?l=learning-computer-programming.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TiGWE/~4/mz5i9L3Agwg" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://learning-computer-programming.blogspot.com/feeds/5762057284830098140/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://learning-computer-programming.blogspot.com/2008/08/creating-simple-countdown-timer-using_14.html#comment-form" title="3 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/33629562/posts/default/5762057284830098140?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/33629562/posts/default/5762057284830098140?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/TiGWE/~3/mz5i9L3Agwg/creating-simple-countdown-timer-using_14.html" title="Creating a Simple Countdown Timer Using JavaScript II...Using getElementById() Method" /><author><name>Arvind Gupta</name><uri>http://www.blogger.com/profile/17199066124402939022</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="23" height="32" src="http://one.arvind.googlepages.com/arvind_gupta_photo.jpg" /></author><thr:total>3</thr:total><feedburner:origLink>http://learning-computer-programming.blogspot.com/2008/08/creating-simple-countdown-timer-using_14.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0AERXg7fCp7ImA9WxdbFkw.&quot;"><id>tag:blogger.com,1999:blog-33629562.post-3952372380028316543</id><published>2008-08-13T12:40:00.000+05:30</published><updated>2008-08-13T12:45:04.604+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-08-13T12:45:04.604+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Web" /><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript" /><category scheme="http://www.blogger.com/atom/ns#" term="Recursion" /><category scheme="http://www.blogger.com/atom/ns#" term="Methods" /><category scheme="http://www.blogger.com/atom/ns#" term="Useful Scripts" /><category scheme="http://www.blogger.com/atom/ns#" term="Tricks" /><category scheme="http://www.blogger.com/atom/ns#" term="HTML" /><title>Creating a Simple Countdown Timer Using JavaScript</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/mpkpHMcFYiKuZ9s5sIadr1lt6EE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/mpkpHMcFYiKuZ9s5sIadr1lt6EE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/mpkpHMcFYiKuZ9s5sIadr1lt6EE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/mpkpHMcFYiKuZ9s5sIadr1lt6EE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p align="center"&gt;&lt;img src="http://one.arvind.googlepages.com/js_count_down_timer01.gif" alt="Creating a Simple Countdown Timer Using JavaScript " width="252" height="363"&gt;&lt;/p&gt;
&lt;p&gt;Some JavaScripting today! We are going to create a simple countdown timer using 
  JavaScript. What&amp;#8217;s the use? Umm, I really am not creative enough to find 
  any of its perfect use but it could be used somewhere, sometimes&amp;#8230;and there 
  is no harm in learning something even when there seems to be no potential use 
  of it. Who knows maybe you&amp;#8217;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&amp;#8217;t wanna miss this!&lt;/p&gt;
&lt;p&gt;This time , let&amp;#8217;s start off with the code first:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&lt;font color="#000000"&gt;
  &amp;lt;!DOCTYPE HTML PUBLIC &lt;font color="#408080"&gt;&amp;quot;-//W3C//DTD HTML 4.01 Transitional//EN&amp;quot;&lt;/font&gt;&amp;gt;
  &amp;lt;html&amp;gt;
  &amp;lt;head&amp;gt;
  &amp;lt;title&amp;gt;JavaScript Countdown Timer&amp;lt;/title&amp;gt;
  &amp;lt;meta http-equiv=&lt;font color="#408080"&gt;&amp;quot;Content-Type&amp;quot;&lt;/font&gt; content=&lt;font color="#408080"&gt;&amp;quot;text/html; charset=iso-8859-1&amp;quot;&lt;/font&gt;&amp;gt;
  &amp;lt;script language=&lt;font color="#408080"&gt;&amp;quot;JavaScript&amp;quot;&lt;/font&gt; type=&lt;font color="#408080"&gt;&amp;quot;text/JavaScript&amp;quot;&lt;/font&gt;&amp;gt;
  &lt;font color="#008000"&gt;//to store timeout ID&lt;/font&gt;
  &lt;font color="#0000ff"&gt;var&lt;/font&gt; tID;
  &lt;font color="#0000ff"&gt;function&lt;/font&gt; tickTimer(t)
  {
    &lt;font color="#008000"&gt;//if time is in range&lt;/font&gt;
    &lt;font color="#0000ff"&gt;if&lt;/font&gt;(t&amp;gt;=&lt;font color="#ff0000"&gt;0&lt;/font&gt;)
    {
      document.writeln(t);
      t=t-&lt;font color="#ff0000"&gt;1&lt;/font&gt;;
      tID=setTimeout(&lt;font color="#408080"&gt;&amp;quot;tickTimer('&amp;quot;&lt;/font&gt;+t+&lt;font color="#408080"&gt;&amp;quot;')&amp;quot;&lt;/font&gt;,&lt;font color="#ff0000"&gt;1000&lt;/font&gt;);
    }
    &lt;font color="#008000"&gt;//stop the timeout event&lt;/font&gt;
    &lt;font color="#0000ff"&gt;else&lt;/font&gt;
    {
      killTimer(tID);
      document.writeln(&lt;font color="#408080"&gt;&amp;quot;&amp;lt;br /&amp;gt; &amp;lt;font color='#ff0000'&amp;gt;Time Out!&amp;lt;/font&amp;gt;&amp;quot;&lt;/font&gt;);
    }
  }

  &lt;font color="#008000"&gt;//function to stop the timeout event&lt;/font&gt;
  &lt;font color="#0000ff"&gt;function&lt;/font&gt; killTimer(id)
  {
    clearTimeout(id);
  }
  &amp;lt;/script&amp;gt;
  &amp;lt;/head&amp;gt;

  &amp;lt;body onLoad=&lt;font color="#408080"&gt;&amp;quot;tickTimer(10)&amp;quot;&lt;/font&gt; onUnload=&lt;font color="#408080"&gt;&amp;quot;killTimer(tID)&amp;quot;&lt;/font&gt;&amp;gt;
  &amp;lt;/body&amp;gt;
  &amp;lt;/html&amp;gt;
&lt;/font&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
  Now let&amp;#8217;s analyze the code:&lt;/p&gt;
&lt;p&gt;&lt;font size="5"&gt;1.&lt;/font&gt; We have created two functions &lt;code&gt;tickTimer(&lt;/code&gt;) 
  and &lt;cpde&gt;&lt;code&gt;killTimer()&lt;/code&gt;&lt;/cpde&gt;.&lt;br&gt;
  &lt;font size="5"&gt;2. &lt;/font&gt;We have defined two event handlers &lt;code&gt;onLoad&lt;/code&gt; 
  and &lt;code&gt;onUnload&lt;/code&gt; which&amp;#8217;d call the respective functions at respective 
  events.&lt;/p&gt;
&lt;p&gt;When the code above (as a web page) is executed, it&amp;#8217;d proceed as:&lt;/p&gt;
&lt;p&gt;&lt;font size="5"&gt;1. &lt;/font&gt;First the &lt;code&gt;onLoad&lt;/code&gt; event calls&lt;code&gt; tickTimer&lt;/code&gt; 
  function with the initial time, the countdown timer has to be ticked down form. 
&lt;/p&gt;
&lt;p&gt;&lt;font size="5"&gt;2.&lt;/font&gt; The function displays the initial time remaining, 
  does some calculations and calls a method &lt;code&gt;setTimeout()&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;font size="5"&gt;3. &lt;/font&gt;The &lt;code&gt;setTimeout&lt;/code&gt; function now calls the 
  function passed, every 1000 milliseconds 1 second). On setting the timeout event 
  this method returns a unique ID which would be used to stop the timeout event 
  when needed (&lt;code&gt;onUnload&lt;/code&gt; or when timer has ticked down to 0).&lt;/p&gt;
&lt;p&gt;One thing you may get confused with is how without loop or anything as such, 
  are we able to count the timer down. Answer is, because JavaScript is an event 
  driven language. First, we are defining a body &lt;code&gt;onLoad&lt;/code&gt; event to 
  make a call to some function as the web page is loaded. Second, we are defining 
  a timeout event that would call the function itself (recursive call) every one 
  second indefinitely until the timeout event is cleared. We are clearing the 
  timeout either when the countdown timer reaches 0 or when the page gets unloaded 
  (&lt;code&gt;onUnload&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;Had JavaScript not been an event driven language, we&amp;#8217;d need to have a 
  loop to check when a second has elapsed and update the variable accordingly. 
  Luckily we don&amp;#8217;t have to!&lt;/p&gt;
&lt;p&gt;But as it is, can we embed or place the above timer in a web page the way we 
  want, styled and perfectly aligned. Or how about a single number getting counted 
  down rather than showing all the numbers as the countdown proceeds. We&amp;#8217;ll 
  see that in the next post!&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Previous Posts:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/08/evaluatingexecuting-php-code-at-run.html"&gt;Evaluating/Executing 
      PHP Code at Run-Time Using eval() Function&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/08/blogger-changing-templates-without.html"&gt;Blogger: 
      Changing Templates without Loosing Widgets&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/08/how-do-i-color-highlight-php-source.html"&gt;How 
      Do I Color-Highlight PHP Source Codes&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/08/web-scraping-gathering-related-searches.html"&gt;Web 
      Scraping: Gathering &amp;quot;Related Searches&amp;quot; Keyword Data From Google 
      Search Results&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/06/basic-web-scraping-scraping-google.html"&gt;Web 
      Scraping: Pulling Out Data From Google Search Results&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/33629562-3952372380028316543?l=learning-computer-programming.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TiGWE/~4/Rk0atstmXzo" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://learning-computer-programming.blogspot.com/feeds/3952372380028316543/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://learning-computer-programming.blogspot.com/2008/08/creating-simple-countdown-timer-using.html#comment-form" title="5 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/33629562/posts/default/3952372380028316543?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/33629562/posts/default/3952372380028316543?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/TiGWE/~3/Rk0atstmXzo/creating-simple-countdown-timer-using.html" title="Creating a Simple Countdown Timer Using JavaScript" /><author><name>Arvind Gupta</name><uri>http://www.blogger.com/profile/17199066124402939022</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="23" height="32" src="http://one.arvind.googlepages.com/arvind_gupta_photo.jpg" /></author><thr:total>5</thr:total><feedburner:origLink>http://learning-computer-programming.blogspot.com/2008/08/creating-simple-countdown-timer-using.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CU4CSHo-cCp7ImA9WxdbEks.&quot;"><id>tag:blogger.com,1999:blog-33629562.post-3278430630181304344</id><published>2008-08-09T12:08:00.000+05:30</published><updated>2008-08-09T12:09:29.458+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-08-09T12:09:29.458+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="PHP" /><category scheme="http://www.blogger.com/atom/ns#" term="Methods" /><category scheme="http://www.blogger.com/atom/ns#" term="Useful Scripts" /><category scheme="http://www.blogger.com/atom/ns#" term="Tricks" /><category scheme="http://www.blogger.com/atom/ns#" term="HTML" /><title>Evaluating/Executing PHP Code at Run-Time Using eval() Function</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/3yEEEtL3jDclKZuiOhYPDZfGsIU/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/3yEEEtL3jDclKZuiOhYPDZfGsIU/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/3yEEEtL3jDclKZuiOhYPDZfGsIU/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/3yEEEtL3jDclKZuiOhYPDZfGsIU/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;Let&amp;#8217;s see some examples:&lt;code&gt;&lt;span style="color: #000000"&gt;&lt;span style="color: #0000BB"&gt;&lt;br /&gt;
  &lt;br /&gt;
  &lt;/span&gt;&lt;span style="color: #007700"&gt;eval(&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"echo&amp;nbsp;'hello';"&lt;/span&gt;&lt;span style="color: #007700"&gt;); 
  &lt;/span&gt;&lt;/span&gt; &lt;/code&gt; &lt;/p&gt;
&lt;p&gt;
  Which is equivalent to:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&lt;span style="color: #000000"&gt;&lt;span style="color: #007700"&gt;echo&amp;nbsp;&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'hello'&lt;/span&gt;&lt;span style="color: #007700"&gt;; 
  &lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt; One more example:&lt;/p&gt;
&lt;code&gt;&lt;span style="color: #000000"&gt;
&lt;span style="color: #0000BB"&gt;&amp;lt;?php
&lt;br /&gt;
&lt;br /&gt;$n&lt;/span&gt;&lt;span style="color: #007700"&gt;=&lt;/span&gt;&lt;span style="color: #0000BB"&gt;10&lt;/span&gt;&lt;span style="color: #007700"&gt;;
&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$code&lt;/span&gt;&lt;span style="color: #007700"&gt;=&lt;/span&gt;&lt;span style="color: #DD0000"&gt;''&lt;/span&gt;&lt;span style="color: #007700"&gt;;
&lt;br /&gt;
&lt;br /&gt;for(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$i&lt;/span&gt;&lt;span style="color: #007700"&gt;=&lt;/span&gt;&lt;span style="color: #0000BB"&gt;0&lt;/span&gt;&lt;span style="color: #007700"&gt;;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$i&lt;/span&gt;&lt;span style="color: #007700"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$n&lt;/span&gt;&lt;span style="color: #007700"&gt;;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$i&lt;/span&gt;&lt;span style="color: #007700"&gt;++)

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$code&lt;/span&gt;&lt;span style="color: #007700"&gt;.=&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"echo&amp;nbsp;$i;"&lt;/span&gt;&lt;span style="color: #007700"&gt;;
&lt;br /&gt;
&lt;br /&gt;eval(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$code&lt;/span&gt;&lt;span style="color: #007700"&gt;);
&lt;br /&gt;
&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;?&amp;gt;&lt;/span&gt;
&lt;/span&gt;
&lt;/code&gt;
&lt;p&gt;Here the code to be evaluated is generated at run-time too.&lt;/p&gt;
&lt;p&gt;The code to be evaluated could be stored somewhere (like in a file or in database) 
  and later can be retrieved and evaluated.&lt;/p&gt;
&lt;p&gt;As an example, below I&amp;#8217;m providing the source code which would create 
  a page that could be used to run PHP code. It&amp;#8217;d provide a HTML textarea 
  for you to type in the code which would then be executed and displayed. Be warned 
  however that this kind of page is extremely vulnerable and an open invitation 
  to hackers as anybody can use it to execute code on the server it is put in. 
  so DON&amp;#8217;T put this onto tour or anybody else&amp;#8217;s server you have access 
  to. It&amp;#8217;d also be advisable to get off the internet before even trying 
  it on your local server and delete the file afterwards. Believe me I&amp;#8217;ve 
  experienced hackers trying to access even local servers!&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&lt;span style="color: #000000"&gt; &lt;span style="color: #0000BB"&gt;&amp;lt;?php&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;echo&amp;nbsp;&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"&amp;lt;?xml&amp;nbsp;version=\"1.0\"&amp;nbsp;encoding=\"iso-8859-1\"?"&lt;/span&gt;&lt;span style="color: #007700"&gt;.&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"&amp;gt;"&lt;/span&gt;&lt;span style="color: #007700"&gt;;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;?&amp;gt; 
  &lt;br /&gt;
  &lt;/span&gt;&amp;lt;!DOCTYPE&amp;nbsp;html&amp;nbsp;PUBLIC&amp;nbsp;"-//W3C//DTD&amp;nbsp;XHTML&amp;nbsp;1.0&amp;nbsp;Transitional//EN"&amp;nbsp;"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&amp;gt; 
  &lt;br /&gt;
  &amp;lt;html&amp;nbsp;xmlns="http://www.w3.org/1999/xhtml"&amp;gt; &lt;br /&gt;
  &amp;lt;head&amp;gt; &lt;br /&gt;
  &amp;lt;title&amp;gt;Untitled&amp;nbsp;Document&amp;lt;/title&amp;gt; &lt;br /&gt;
  &amp;lt;meta&amp;nbsp;http-equiv="Content-Type"&amp;nbsp;content="text/html;&amp;nbsp;charset=iso-8859-1"&amp;nbsp;/&amp;gt; 
  &lt;br /&gt;
  &amp;lt;/head&amp;gt; &lt;br /&gt;
  &lt;br /&gt;
  &amp;lt;body&amp;gt; &lt;br /&gt;
  &amp;lt;h2&amp;gt;Run&amp;nbsp;Script&amp;lt;/h2&amp;gt; &lt;br /&gt;
  &amp;lt;form&amp;nbsp;name="form1"&amp;nbsp;id="form1"&amp;nbsp;method="get"&amp;nbsp;action=""&amp;gt; 
  &lt;br /&gt;
  &amp;nbsp;&amp;nbsp;&amp;lt;p&amp;gt; &lt;br /&gt;
  &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;textarea&amp;nbsp;name="code"&amp;nbsp;cols="50"&amp;nbsp;rows="15"&amp;nbsp;id="code"&amp;gt;&amp;lt;/textarea&amp;gt; 
  &lt;br /&gt;
  &amp;nbsp;&amp;nbsp;&amp;lt;/p&amp;gt; &lt;br /&gt;
  &amp;nbsp;&amp;nbsp;&amp;lt;p&amp;gt; &lt;br /&gt;
  &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;input&amp;nbsp;type="submit"&amp;nbsp;name="Submit"&amp;nbsp;value="Execute!"&amp;nbsp;/&amp;gt; 
  &lt;br /&gt;
  &amp;nbsp;&amp;nbsp;&amp;lt;/p&amp;gt; &lt;br /&gt;
  &amp;lt;/form&amp;gt; &lt;br /&gt;
  &amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;Output:&amp;lt;br&amp;nbsp;/&amp;gt; &lt;br /&gt;
  &amp;nbsp;&amp;nbsp;-----------&amp;lt;/strong&amp;gt;&amp;lt;/p&amp;gt; &lt;br /&gt;
  &lt;span style="color: #0000BB"&gt;&amp;lt;?php &lt;br /&gt;
  &lt;/span&gt;&lt;span style="color: #007700"&gt;if(isset(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$_GET&lt;/span&gt;&lt;span style="color: #007700"&gt;[&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'Submit'&lt;/span&gt;&lt;span style="color: #007700"&gt;])) 
  &lt;br /&gt;
  { &lt;br /&gt;
  &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$code&lt;/span&gt;&lt;span style="color: #007700"&gt;=&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$_GET&lt;/span&gt;&lt;span style="color: #007700"&gt;[&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'code'&lt;/span&gt;&lt;span style="color: #007700"&gt;]; 
  &lt;br /&gt;
  &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
  &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;eval(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$code&lt;/span&gt;&lt;span style="color: #007700"&gt;); 
  &lt;br /&gt;
  } &lt;br /&gt;
  &lt;/span&gt;&lt;span style="color: #0000BB"&gt;?&amp;gt; &lt;br /&gt;
  &lt;/span&gt; &lt;br /&gt;
  &amp;lt;/body&amp;gt; &lt;br /&gt;
  &amp;lt;/html&amp;gt; &lt;/span&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p align="center"&gt;&lt;code&gt;&lt;span style="color: #000000"&gt;&lt;img src="http://one.arvind.googlepages.com/eval_scrnsht.JPG" alt="Evaluating/Executing PHP Code at Run-Time Using eval() Function " width="363" height="550" /&gt;&lt;/span&gt;&lt;/code&gt; 
&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Previous Posts:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/08/blogger-changing-templates-without.html"&gt;Blogger: 
      Changing Templates without Loosing Widgets&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/08/how-do-i-color-highlight-php-source.html"&gt;How 
      Do I Color-Highlight PHP Source Codes&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/08/web-scraping-gathering-related-searches.html"&gt;Web 
      Scraping: Gathering &amp;quot;Related Searches&amp;quot; Keyword Data From Google 
      Search Results&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/06/basic-web-scraping-scraping-google.html"&gt;Web 
      Scraping: Pulling Out Data From Google Search Results&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/06/creating-simple-html-form-validation.html"&gt;Creating 
      a Simple Form Validation Script Using JavaScript&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/33629562-3278430630181304344?l=learning-computer-programming.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TiGWE/~4/LyTFj9EC50U" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://learning-computer-programming.blogspot.com/feeds/3278430630181304344/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://learning-computer-programming.blogspot.com/2008/08/evaluatingexecuting-php-code-at-run.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/33629562/posts/default/3278430630181304344?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/33629562/posts/default/3278430630181304344?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/TiGWE/~3/LyTFj9EC50U/evaluatingexecuting-php-code-at-run.html" title="Evaluating/Executing PHP Code at Run-Time Using eval() Function" /><author><name>Arvind Gupta</name><uri>http://www.blogger.com/profile/17199066124402939022</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="23" height="32" src="http://one.arvind.googlepages.com/arvind_gupta_photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://learning-computer-programming.blogspot.com/2008/08/evaluatingexecuting-php-code-at-run.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkAARnw7fCp7ImA9WxdbEUQ.&quot;"><id>tag:blogger.com,1999:blog-33629562.post-2779841419541651735</id><published>2008-08-08T15:25:00.003+05:30</published><updated>2008-08-08T15:49:07.204+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-08-08T15:49:07.204+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Methods" /><category scheme="http://www.blogger.com/atom/ns#" term="Blogger" /><category scheme="http://www.blogger.com/atom/ns#" term="Miscellaneous" /><category scheme="http://www.blogger.com/atom/ns#" term="Tricks" /><category scheme="http://www.blogger.com/atom/ns#" term="HTML" /><title>Blogger: Changing Templates without Loosing Widgets</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/9eFjCyGYvKw0CaPFOjEPUiNkIrg/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/9eFjCyGYvKw0CaPFOjEPUiNkIrg/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/9eFjCyGYvKw0CaPFOjEPUiNkIrg/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/9eFjCyGYvKw0CaPFOjEPUiNkIrg/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p align="center"&gt;&lt;img src="http://one.arvind.googlepages.com/blogger-logo.jpg" alt="Blogger: Changing Templates without Loosing Widgets " width="213" height="213" /&gt;&lt;/p&gt;
&lt;p&gt;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 (&amp;gt;180!), man could I afford to loose that? Of course NOT!&lt;/p&gt;
&lt;p&gt;Good thing was switching to one of the templates provided by Blogger wouldn&amp;#8217;t 
  make me loose those widgets. Bad thing is I don&amp;#8217;t like those templates. 
  Those are all too old, excessively used everywhere and 2-column ones.&lt;/p&gt;
&lt;p&gt;So what did I do to save my widgets when changing to a third party Blogger 
  template? Read along to know&amp;#8230;(this might look like a crappy landing page 
  that&amp;#8217;d sell you something, believe me its NOT!)&lt;/p&gt;
&lt;p&gt;If you too are facing the same problem you can take these steps to save your 
  widgets:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;STEPS:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="5"&gt;1.&lt;/font&gt; Start off by going to Layout-&amp;gt; Edit HTML then click 
  on Expand Widget Template check box.&lt;/p&gt;
&lt;p&gt;&lt;font size="5"&gt;2.&lt;/font&gt; Search for &lt;code&gt;&lt;strong&gt;&amp;lt;b:widget&lt;/strong&gt;&lt;/code&gt; 
  in the template code and copy the widget section code.&lt;br /&gt;
  e.g.:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;...&lt;br /&gt;&amp;lt;div id='sidebar-wrapper'&amp;gt;&lt;br /&gt;
  &amp;lt;b:section class='sidebar' id='sidebar' preferred='yes'&amp;gt;&lt;br /&gt;
  &lt;font color="#FF0000"&gt;&amp;lt;b:widget id='HTML1' locked='false' title='Search this 
  Blog' type='HTML'&amp;gt;&lt;br /&gt;
  &amp;lt;b:includable id='main'&amp;gt;&lt;br /&gt;
  &amp;lt;!-- only display title if it's non-empty --&amp;gt;&lt;br /&gt;
  &amp;lt;b:if cond='data:title != &amp;amp;quot;&amp;amp;quot;'&amp;gt;&lt;br /&gt;
  &amp;lt;h2 class='title'&amp;gt;&amp;lt;data:title/&amp;gt;&amp;lt;/h2&amp;gt;&lt;br /&gt;
  &amp;lt;/b:if&amp;gt;&lt;br /&gt;
  &amp;lt;div class='widget-content'&amp;gt;&lt;br /&gt;
  &amp;lt;data:content/&amp;gt;&lt;br /&gt;
  &amp;lt;/div&amp;gt;&lt;/font&gt; &lt;br /&gt; &lt;br /&gt;
 &lt;font color="#FF0000"&gt;&amp;lt;b:include name='quickedit'/&amp;gt;&lt;br /&gt;
  &amp;lt;/b:includable&amp;gt;&lt;br /&gt;
  &amp;lt;/b:widget&amp;gt;&lt;/font&gt;&lt;br /&gt;
  &amp;lt;b:widget id='LinkList1' locked='false' title='Recent Posts' type='LinkList'&amp;gt;&lt;br /&gt;
  &amp;lt;b:includable id='main'&amp;gt; &lt;br /&gt; &lt;br /&gt;
&amp;lt;b:if cond='data:title'&amp;gt;&amp;lt;h2&amp;gt;&amp;lt;data:title/&amp;gt;&amp;lt;/h2&amp;gt;&amp;lt;/b:if&amp;gt;&lt;br /&gt;
  &amp;lt;div class='widget-content'&amp;gt;&lt;br /&gt;
  &amp;lt;ul&amp;gt;&lt;br /&gt;
  ...
&lt;/code&gt;&lt;/p&gt;
&lt;p&gt; Do it as many times as needed to copy all the widgets. Paste them one after 
  to other in Notepad. You can leave the unnecessary ones such as Header, Blog 
  (There is a widget for this too, shows the posts) etc. the code of which would 
  look something like below:&lt;/p&gt;
&lt;p&gt;No need to copy these:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;code&gt;&amp;lt;b:widget id='Header1' locked='true' title='For Testing Purpose 
    (Header)' type='Header'&amp;gt;&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code&gt;&amp;lt;b:widget id='Blog1' locked='true' title='Blog Posts' type='Blog'&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt; &lt;font size="5"&gt;3.&lt;/font&gt; Now copy the new template code by opening the XML 
  file in another Notepad. Paste it in Blogger deleting the old template code.&lt;/p&gt;
&lt;p&gt;&lt;font size="5"&gt;4.&lt;/font&gt; Find the following line in the newly pasted template 
  code:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;...&lt;br /&gt;&amp;lt;div id='sidebar-wrapper'&amp;gt;&lt;br /&gt;
  &amp;lt;b:section class='sidebar' id='sidebar' preferred='yes'&amp;gt;&lt;br /&gt;
  &lt;font color="#FF0000"&gt;[--PASTE WIDGETCODE HERE--]&lt;/font&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="5"&gt;5.&lt;/font&gt; Paste all the widget codes previously copied there 
  right after the &lt;code&gt;&amp;lt;b:section&lt;/code&gt; line. &lt;/p&gt;
&lt;p&gt;&lt;font size="5"&gt;6. &lt;/font&gt;Save the template.&lt;/p&gt;
&lt;p&gt;&lt;font size="5"&gt;7.&lt;/font&gt; If you had not copied some unnecessary widget codes 
  from the original template, Blogger might ask you to confirm their deletion. 
  Confirm this and SAVE the template.&lt;/p&gt;
&lt;p&gt;&lt;font size="5"&gt;8.&lt;/font&gt; Done!&lt;/p&gt;
&lt;p&gt;Doing this you&amp;#8217;d save existing widget from getting deleted when switching 
  template but the widgets will NOT be arranged or placed in any meaningful manner 
  (they&amp;#8217;d all be in a sidebar). To re-arrange them in the manner you want 
  just go to Layout-&amp;gt; Page Elements and drag drop the widgets as required, 
  click save. You&amp;#8217;re done!&lt;/p&gt;
&lt;p align="center"&gt;&lt;img src="http://one.arvind.googlepages.com/blogger_widgets_01.gif" alt="Blogger: Changing Templates without Loosing Widgets  - Rearrange the Widgets" width="367" height="480" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Previous Posts:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/08/how-do-i-color-highlight-php-source.html"&gt;How 
      Do I Color-Highlight PHP Source Codes&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/08/web-scraping-gathering-related-searches.html"&gt;Web 
      Scraping: Gathering &amp;quot;Related Searches&amp;quot; Keyword Data From Google 
      Search Results&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/06/basic-web-scraping-scraping-google.html"&gt;Web 
      Scraping: Pulling Out Data From Google Search Results&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/06/creating-simple-html-form-validation.html"&gt;Creating 
      a Simple Form Validation Script Using JavaScript&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/06/creating-simple-html-form-validation.html"&gt;Deigning 
      a Simple HTML Menu-Bar Using CSS&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/33629562-2779841419541651735?l=learning-computer-programming.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TiGWE/~4/cqzaLgzQXdM" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://learning-computer-programming.blogspot.com/feeds/2779841419541651735/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://learning-computer-programming.blogspot.com/2008/08/blogger-changing-templates-without.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/33629562/posts/default/2779841419541651735?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/33629562/posts/default/2779841419541651735?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/TiGWE/~3/cqzaLgzQXdM/blogger-changing-templates-without.html" title="Blogger: Changing Templates without Loosing Widgets" /><author><name>Arvind Gupta</name><uri>http://www.blogger.com/profile/17199066124402939022</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="23" height="32" src="http://one.arvind.googlepages.com/arvind_gupta_photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://learning-computer-programming.blogspot.com/2008/08/blogger-changing-templates-without.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A0EGQXk9fCp7ImA9WxdUFko.&quot;"><id>tag:blogger.com,1999:blog-33629562.post-250372372513652730</id><published>2008-08-02T17:48:00.001+05:30</published><updated>2008-08-02T17:50:20.764+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-08-02T17:50:20.764+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="PHP" /><category scheme="http://www.blogger.com/atom/ns#" term="Methods" /><category scheme="http://www.blogger.com/atom/ns#" term="Functions" /><category scheme="http://www.blogger.com/atom/ns#" term="Miscellaneous" /><category scheme="http://www.blogger.com/atom/ns#" term="Tricks" /><category scheme="http://www.blogger.com/atom/ns#" term="Syntax Highlighting" /><category scheme="http://www.blogger.com/atom/ns#" term="HTML" /><title>How Do I Color-Highlight PHP Source Codes</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/8TXdxSdNuY5tK_KZQVkOPiiteqQ/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/8TXdxSdNuY5tK_KZQVkOPiiteqQ/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/8TXdxSdNuY5tK_KZQVkOPiiteqQ/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/8TXdxSdNuY5tK_KZQVkOPiiteqQ/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;If you&amp;#8217;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.&lt;/p&gt;
&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;&lt;font size="5"&gt;1. &lt;/font&gt;If have set-up PHP as explained in &lt;a href="http://learning-computer-programming.blogspot.com/2008/04/configuring-apache-web-server-and-php.html"&gt;&lt;em&gt;Configuring 
  Apache Web Server and PHP&lt;/em&gt;&lt;/a&gt; then you can just name your PHP files like 
  &amp;#8220;filename.phps&amp;#8221; 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.&lt;/p&gt;
&lt;p align="center"&gt;&lt;img src="http://one.arvind.googlepages.com/source_highlight01.JPG" alt="PHP Source Code Highlighting - Using .phps Files" width="373" height="451" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="5"&gt;2.&lt;/font&gt; You can use the following function to highlight any 
  PHP (.php) script file:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&lt;span style="color: #000000"&gt;&lt;span style="color: #0000BB"&gt;highlight_file&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'filename.php'&lt;span style="color: #007700"&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span style="color: #007700"&gt;; 
  &lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;You just have to pass the filename to this function and PHP will highlight 
  and output the code to the browser.&lt;/p&gt;
&lt;p&gt;Main benefit with this is you can embed source code into your web pages wherever 
  you want.&lt;/p&gt;
&lt;p&gt;e.g.:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&lt;span style="color: #000000"&gt; &lt;span style="color: #0000BB"&gt;&amp;lt;?php &lt;br /&gt;
  &lt;br /&gt;
  &lt;/span&gt;&lt;span style="color: #007700"&gt;echo&amp;nbsp;&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"&amp;lt;h1&amp;gt;Blah&amp;nbsp;Blah&amp;nbsp;Blog&amp;lt;/h1&amp;gt;"&lt;/span&gt;&lt;span style="color: #007700"&gt;; 
  &lt;br /&gt;
  echo&amp;nbsp;&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"&amp;lt;h2&amp;gt;Highlighting&amp;nbsp;PHP&amp;nbsp;Source&amp;nbsp;Code&amp;lt;/h2&amp;gt;"&lt;/span&gt;&lt;span style="color: #007700"&gt;; 
  &lt;br /&gt;
  &lt;br /&gt;
  echo&amp;nbsp;&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"&amp;lt;p&amp;gt;blah&amp;nbsp;blah&amp;nbsp;blah!!&amp;lt;/p&amp;gt;"&lt;/span&gt;&lt;span style="color: #007700"&gt;; 
  &lt;br /&gt;
  echo&amp;nbsp;&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"&amp;lt;p&amp;gt;Write&amp;nbsp;anything&amp;nbsp;you&amp;nbsp;want&amp;nbsp;and&amp;nbsp;embed&amp;nbsp;source&amp;nbsp;code&amp;nbsp;(highlighted)&amp;lt;/p&amp;gt;"&lt;/span&gt;&lt;span style="color: #007700"&gt;; 
  &lt;br /&gt;
  echo&amp;nbsp;&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"&amp;lt;p&amp;gt;Embedded&amp;nbsp;source&amp;nbsp;code&amp;nbsp;is&amp;nbsp;listed&amp;nbsp;below:&amp;lt;/p&amp;gt;"&lt;/span&gt;&lt;span style="color: #007700"&gt;; 
  &lt;br /&gt;
  &lt;br /&gt;
  &lt;/span&gt;&lt;span style="color: #0000BB"&gt;highlight_file&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'highlight_file.php'&lt;/span&gt;&lt;span style="color: #007700"&gt;); 
  &lt;br /&gt;
  &lt;br /&gt;
  &lt;/span&gt;&lt;span style="color: #0000BB"&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt; &lt;/p&gt;
&lt;p align="center"&gt;&lt;img src="http://one.arvind.googlepages.com/source_highlight02.JPG" alt="PHP Source Code Highlighting  - Using highlight_file() Function" width="373" height="451" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="5"&gt;3.&lt;/font&gt; There are times when you just want to highlight a 
  single line of code which can be done using:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&lt;span style="color: #000000"&gt;&lt;span style="color: #0000BB"&gt;highlight_file&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'string 
  here'&lt;span style="color: #007700"&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span style="color: #007700"&gt;; 
  &lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;It could be used when you have lost of unrelated lines of code to highlight. 
  In other words, when the codes are not together but are sprinkled throughout 
  the page. For this you don&amp;#8217;t have to create any files to be highlighted, 
  just use this function with thee source code string.&lt;/p&gt;
&lt;p&gt;e.g.:&lt;/p&gt;
&lt;code&gt;&lt;span style="color: #000000"&gt;
&lt;span style="color: #0000BB"&gt;&amp;lt;?php
&lt;br /&gt;
&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #007700"&gt;echo&amp;nbsp;&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"&amp;lt;h1&amp;gt;Blah&amp;nbsp;Blah&amp;nbsp;Blog&amp;lt;/h1&amp;gt;"&lt;/span&gt;&lt;span style="color: #007700"&gt;;
&lt;br /&gt;echo&amp;nbsp;&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"&amp;lt;h2&amp;gt;Highlighting&amp;nbsp;PHP&amp;nbsp;Source&amp;nbsp;Code&amp;lt;/h2&amp;gt;"&lt;/span&gt;&lt;span style="color: #007700"&gt;;
&lt;br /&gt;
&lt;br /&gt;echo&amp;nbsp;&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"&amp;lt;p&amp;gt;First&amp;nbsp;String:&amp;nbsp;&amp;lt;br&amp;nbsp;/&amp;gt;"&lt;/span&gt;&lt;span style="color: #007700"&gt;;
&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;highlight_string&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"&amp;lt;?php&amp;nbsp;echo&amp;nbsp;\"&amp;lt;h1&amp;gt;Blah&amp;nbsp;Blah&amp;nbsp;Blog&amp;lt;/h1&amp;gt;\";&amp;nbsp;?&amp;gt;"&lt;/span&gt;&lt;span style="color: #007700"&gt;);
&lt;br /&gt;
&lt;br /&gt;echo&amp;nbsp;&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"&amp;lt;br&amp;nbsp;/&amp;gt;Second&amp;nbsp;String:&amp;nbsp;&amp;lt;br&amp;nbsp;/&amp;gt;"&lt;/span&gt;&lt;span style="color: #007700"&gt;;
&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;highlight_string&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"&amp;lt;?php&amp;nbsp;foreach($keywords&amp;nbsp;as&amp;nbsp;$keyword)&amp;nbsp;?&amp;gt;"&lt;/span&gt;&lt;span style="color: #007700"&gt;);
&lt;br /&gt;
&lt;br /&gt;echo&amp;nbsp;&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;blah&amp;nbsp;blah&amp;nbsp;blah&amp;nbsp;blah&amp;nbsp;&amp;lt;br&amp;nbsp;/&amp;gt;blah&amp;nbsp;blah&amp;nbsp;blah&amp;lt;/p&amp;gt;"&lt;/span&gt;&lt;span style="color: #007700"&gt;;
&lt;br /&gt;echo&amp;nbsp;&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"&amp;lt;p&amp;gt;Third&amp;nbsp;highlighted&amp;nbsp;String:&amp;nbsp;&amp;lt;br&amp;nbsp;/&amp;gt;"&lt;/span&gt;&lt;span style="color: #007700"&gt;;
&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;highlight_string&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"&amp;lt;?php&amp;nbsp;if(isset($s))&amp;nbsp;?&amp;gt;"&lt;/span&gt;&lt;span style="color: #007700"&gt;);
&lt;br /&gt;
&lt;br /&gt;echo&amp;nbsp;&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"&amp;lt;p&amp;gt;Notice&amp;nbsp;how&amp;nbsp;many&amp;nbsp;unrelated&amp;nbsp;code&amp;nbsp;strings&amp;nbsp;are&amp;nbsp;here.&amp;nbsp;The&amp;nbsp;best&amp;nbsp;way&amp;nbsp;to&amp;nbsp;format&amp;nbsp;them&amp;nbsp;in&amp;nbsp;this&amp;nbsp;condition&amp;nbsp;is&amp;nbsp;to&amp;nbsp;use&amp;nbsp;"&lt;/span&gt;&lt;span style="color: #007700"&gt;;
&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;highlight_string&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"&amp;lt;?php&amp;nbsp;highlight_string(\"string\");&amp;nbsp;?&amp;gt;"&lt;/span&gt;&lt;span style="color: #007700"&gt;);
&lt;br /&gt;echo&amp;nbsp;&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"function&amp;nbsp;&amp;lt;/p&amp;gt;"&lt;/span&gt;&lt;span style="color: #007700"&gt;;
&lt;br /&gt;
&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;?&amp;gt;&lt;/span&gt;
&lt;/span&gt;
&lt;/code&gt;
&lt;p&gt;Which would show up like below:&lt;/p&gt;
&lt;p align="center"&gt;&lt;img src="http://one.arvind.googlepages.com/source_highlight03.JPG" alt="PHP Source Code Highlighting  - Using highlight_string() Function" width="373" height="451" /&gt;&lt;/p&gt;
&lt;p&gt;One interesting thing that you can play with, regarding syntax highlighting 
  is the &amp;#8220;php.ini&amp;#8221; file. Look for these lines in that file:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;; Colors for Syntax Highlighting mode. Anything that's acceptable in&lt;br /&gt;
  ; &amp;lt;span style=&amp;quot;color: ???????&amp;quot;&amp;gt; would work.&lt;br /&gt;
  highlight.string = #DD0000&lt;br /&gt;
  highlight.comment = #FF9900&lt;br /&gt;
  highlight.keyword = #007700&lt;br /&gt;
  highlight.bg = #FFFFFF&lt;br /&gt;
  highlight.default = #0000BB&lt;br /&gt;
  highlight.html = #000000&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Here, as you can see, the colors for highlighting different parts of the code 
  are defined. You can change these to alter the colors that are use for highlighting. 
  Colors are in HEX RGB format (same as HTML color code).&lt;/p&gt;
&lt;p&gt;&lt;font size="4"&gt;NOTE:&lt;/font&gt; If you don&amp;#8217;t seem to be able to see the source 
  code highlighted you might need remove the &amp;quot;;&amp;quot; (semi-colons) from 
  the starting of each of the &amp;quot;highlight.&amp;quot; line so it looks like the 
  above code:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;; Colors for Syntax Highlighting mode. Anything that's acceptable in&lt;br /&gt;
  ; &amp;lt;span style=&amp;quot;color: ???????&amp;quot;&amp;gt; would work.&lt;br /&gt;
  &lt;font color="#FF0000"&gt;;&lt;/font&gt;highlight.string = #DD0000&lt;br /&gt;
  &lt;font color="#FF0000"&gt;;&lt;/font&gt;highlight.comment = #FF9900&lt;br /&gt;
  &lt;font color="#FF0000"&gt;;&lt;/font&gt;highlight.keyword = #007700&lt;br /&gt;
  &lt;font color="#FF0000"&gt;;&lt;/font&gt;highlight.bg = #FFFFFF&lt;br /&gt;
  &lt;font color="#FF0000"&gt;;&lt;/font&gt;highlight.default = #0000BB&lt;br /&gt;
  &lt;font color="#FF0000"&gt;;&lt;/font&gt;highlight.html = #000000&lt;/code&gt; &lt;/p&gt;
&lt;p&gt;If only &amp;#8220;.phps&amp;#8221; PHP source files are not getting highlighted, you&amp;#8217;ll 
  need to set-up PHP as described in &lt;a href="http://learning-computer-programming.blogspot.com/2008/04/configuring-apache-web-server-and-php.html"&gt;&lt;em&gt;Configuring 
  Apache Web Server and PHP&lt;/em&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Previous Posts:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/08/web-scraping-gathering-related-searches.html"&gt;Web 
      Scraping: Gathering &amp;quot;Related Searches&amp;quot; Keyword Data From Google 
      Search Results&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/06/basic-web-scraping-scraping-google.html"&gt;Web 
      Scraping: Pulling Out Data From Google Search Results&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/06/creating-simple-html-form-validation.html"&gt;Creating 
      a Simple Form Validation Script Using JavaScript&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/06/creating-simple-html-form-validation.html"&gt;Deigning 
      a Simple HTML Menu-Bar Using CSS &lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/06/blogger-method-to-add-link-to-this-post.html"&gt;Blogger: 
      Method to Add &amp;#8216;Link to This Post&amp;#8217; Widget on Your Posts &lt;/a&gt; 
    &lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/33629562-250372372513652730?l=learning-computer-programming.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TiGWE/~4/jLK-vmKi4Is" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://learning-computer-programming.blogspot.com/feeds/250372372513652730/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://learning-computer-programming.blogspot.com/2008/08/how-do-i-color-highlight-php-source.html#comment-form" title="7 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/33629562/posts/default/250372372513652730?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/33629562/posts/default/250372372513652730?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/TiGWE/~3/jLK-vmKi4Is/how-do-i-color-highlight-php-source.html" title="How Do I Color-Highlight PHP Source Codes" /><author><name>Arvind Gupta</name><uri>http://www.blogger.com/profile/17199066124402939022</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="23" height="32" src="http://one.arvind.googlepages.com/arvind_gupta_photo.jpg" /></author><thr:total>7</thr:total><feedburner:origLink>http://learning-computer-programming.blogspot.com/2008/08/how-do-i-color-highlight-php-source.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkQARH8yfyp7ImA9WxdUFUU.&quot;"><id>tag:blogger.com,1999:blog-33629562.post-8573334290002368620</id><published>2008-08-01T13:33:00.002+05:30</published><updated>2008-08-01T14:15:45.197+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-08-01T14:15:45.197+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Web" /><category scheme="http://www.blogger.com/atom/ns#" term="PHP" /><category scheme="http://www.blogger.com/atom/ns#" term="Useful Scripts" /><category scheme="http://www.blogger.com/atom/ns#" term="Complete Script" /><category scheme="http://www.blogger.com/atom/ns#" term="HTML" /><category scheme="http://www.blogger.com/atom/ns#" term="Web Scraping" /><title>Web Scraping: Gathering "Related Searches" Keyword Data From Google Search Results</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/TFUm06O060MTZOAx1PDGtE3OAnE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/TFUm06O060MTZOAx1PDGtE3OAnE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/TFUm06O060MTZOAx1PDGtE3OAnE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/TFUm06O060MTZOAx1PDGtE3OAnE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p align="center"&gt;&lt;img src="http://one.arvind.googlepages.com/google_search_scraper01.JPG" width="255" height="422" alt="Web Scraping: Gathering &amp;quot;Related Searches&amp;quot; Keyword Data From Google Search Results"/&gt;&lt;/p&gt;
&lt;p&gt;You might first want to read Basic &lt;a href="http://learning-computer-programming.blogspot.com/2008/06/basic-web-scraping-scraping-google.html"&gt;Web 
  Scraping: Pulling Out Data From Google Search Results&lt;/a&gt;. &lt;/p&gt;
&lt;p&gt;In the other Basic Web Scraping post we created a Simple Web Scraper that retrieved 
  Google&amp;#8217;s Search Result Pages for some keyword and scraped the &amp;#8220;Number 
  of Pages&amp;#8221; indexed for the keyword. That was a good starting point in learning 
  web scraping, that&amp;#8217;s why in this post we&amp;#8217;re going to extend that 
  scraper to return one more information, &amp;#8220;Related Keywords&amp;#8221;.&lt;/p&gt;
&lt;p&gt;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 &amp;#8220;related 
  Searches&amp;#8221; are the keywords that Google has evaluated to be related with 
  the one searched for.&lt;/p&gt;
&lt;p&gt;To scrape this, we&amp;#8217;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&amp;#8217;d like:&lt;/p&gt;
&lt;code&gt;&amp;lt;h2 class=r&amp;gt;Searches related to:&amp;lt;b&amp;gt; computer programming&amp;lt;/b&amp;gt;&amp;lt;/h2&amp;gt;&amp;lt;table 
  border=0 cellpadding=0 cellspacing=0 style=&amp;quot;margin-top:6px&amp;quot;&amp;gt;&amp;lt;tr 
  style=&amp;quot;font-size:84%&amp;quot;&amp;gt;&amp;lt;td style=&amp;quot;padding:0 30px 6px 0&amp;quot; 
  valign=top&amp;gt;&amp;lt;a href=&amp;quot;/search?hl=en&amp;amp;client=firefox-a&amp;amp;rls=org.mozilla:en-US:official&amp;amp;hs=lS4&amp;amp;q=computer+programming+schools&amp;amp;revid=92395746&amp;amp;sa=X&amp;amp;oi=revisions_inline&amp;amp;resnum=0&amp;amp;ct=broad-revision&amp;amp;cd=1&amp;quot;&amp;gt;computer 
  programming &amp;lt;b&amp;gt;schools&amp;lt;/b&amp;gt;&amp;lt;/a&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;&amp;amp;nbsp;&amp;lt;/td&amp;gt;&amp;lt;td 
  style=&amp;quot;padding:0 30px 6px 0&amp;quot; valign=top&amp;gt;&amp;lt;a href=&amp;quot;/search?hl=en&amp;amp;client=firefox-a&amp;amp;rls=org.mozilla:en-US:official&amp;amp;hs=lS4&amp;amp;q=computer+programming+careers&amp;amp;revid=92395746&amp;amp;sa=X&amp;amp;oi=revisions_inline&amp;amp;resnum=0&amp;amp;ct=broad-revision&amp;amp;cd=2&amp;quot;&amp;gt;computer 
  programming &amp;lt;b&amp;gt;careers&amp;lt;/b&amp;gt;&amp;lt;/a&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;&amp;amp;nbsp;&amp;lt;/td&amp;gt;&amp;lt;td 
  style=&amp;quot;padding:0 30px 6px 0&amp;quot; valign=top&amp;gt;&amp;lt;a href=&amp;quot;/search?hl=en&amp;amp;client=firefox-a&amp;amp;rls=org.mozilla:en-US:official&amp;amp;hs=lS4&amp;amp;q=computer+programming+languages&amp;amp;revid=92395746&amp;amp;sa=X&amp;amp;oi=revisions_inline&amp;amp;resnum=0&amp;amp;ct=broad-revision&amp;amp;cd=3&amp;quot;&amp;gt;computer 
  programming &amp;lt;b&amp;gt;languages&amp;lt;/b&amp;gt;&amp;lt;/a&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;&amp;amp;nbsp;&amp;lt;/td&amp;gt;&amp;lt;td 
  style=&amp;quot;padding:0 30px 6px 0&amp;quot; valign=top&amp;gt;&amp;lt;a href=&amp;quot;/search?hl=en&amp;amp;client=firefox-a&amp;amp;rls=org.mozilla:en-US:official&amp;amp;hs=lS4&amp;amp;q=computer+programming+c%2B%2B&amp;amp;revid=92395746&amp;amp;sa=X&amp;amp;oi=revisions_inline&amp;amp;resnum=0&amp;amp;ct=broad-revision&amp;amp;cd=4&amp;quot;&amp;gt;computer 
  programming &amp;lt;b&amp;gt;c++&amp;lt;/b&amp;gt;&amp;lt;/a&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;&amp;amp;nbsp;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;lt;tr 
  style=&amp;quot;font-size:84%&amp;quot;&amp;gt;&amp;lt;td style=&amp;quot;padding:0 30px 6px 0&amp;quot; 
  valign=top&amp;gt;&amp;lt;a href=&amp;quot;/search?hl=en&amp;amp;client=firefox-a&amp;amp;rls=org.mozilla:en-US:official&amp;amp;hs=lS4&amp;amp;q=computer+programming+information&amp;amp;revid=92395746&amp;amp;sa=X&amp;amp;oi=revisions_inline&amp;amp;resnum=0&amp;amp;ct=broad-revision&amp;amp;cd=5&amp;quot;&amp;gt;computer 
  programming &amp;lt;b&amp;gt;information&amp;lt;/b&amp;gt;&amp;lt;/a&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;&amp;amp;nbsp;&amp;lt;/td&amp;gt;&amp;lt;td 
  style=&amp;quot;padding:0 30px 6px 0&amp;quot; valign=top&amp;gt;&amp;lt;a href=&amp;quot;/search?hl=en&amp;amp;client=firefox-a&amp;amp;rls=org.mozilla:en-US:official&amp;amp;hs=lS4&amp;amp;q=basic+computer+programming&amp;amp;revid=92395746&amp;amp;sa=X&amp;amp;oi=revisions_inline&amp;amp;resnum=0&amp;amp;ct=broad-revision&amp;amp;cd=6&amp;quot;&amp;gt;&amp;lt;b&amp;gt;basic&amp;lt;/b&amp;gt; 
  computer programming&amp;lt;/a&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;&amp;amp;nbsp;&amp;lt;/td&amp;gt;&amp;lt;td 
  style=&amp;quot;padding:0 30px 6px 0&amp;quot; valign=top&amp;gt;&amp;lt;a href=&amp;quot;/search?hl=en&amp;amp;client=firefox-a&amp;amp;rls=org.mozilla:en-US:official&amp;amp;hs=lS4&amp;amp;q=computer+programming+for+dummies&amp;amp;revid=92395746&amp;amp;sa=X&amp;amp;oi=revisions_inline&amp;amp;resnum=0&amp;amp;ct=broad-revision&amp;amp;cd=7&amp;quot;&amp;gt;computer 
  programming &amp;lt;b&amp;gt;for dummies&amp;lt;/b&amp;gt;&amp;lt;/a&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;&amp;amp;nbsp;&amp;lt;/td&amp;gt;&amp;lt;td 
  style=&amp;quot;padding:0 30px 6px 0&amp;quot; valign=top&amp;gt;&amp;lt;a href=&amp;quot;/search?hl=en&amp;amp;client=firefox-a&amp;amp;rls=org.mozilla:en-US:official&amp;amp;hs=lS4&amp;amp;q=game+programming&amp;amp;revid=92395746&amp;amp;sa=X&amp;amp;oi=revisions_inline&amp;amp;resnum=0&amp;amp;ct=broad-revision&amp;amp;cd=8&amp;quot;&amp;gt;&amp;lt;b&amp;gt;game&amp;lt;/b&amp;gt; 
  programming&amp;lt;/a&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;&amp;amp;nbsp;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;lt;/table&amp;gt;&lt;/code&gt;
&lt;p&gt;Remember our goal here is to find out certain footprint or consistent block 
  in the code (which always will be on every page we request), out of which the 
  needed data (Related Searches) can be pulled out.&lt;/p&gt;
&lt;p&gt;Here, we can safely assume it to be:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&amp;lt;h2 class=r&amp;gt;Searches related to:&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;and&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;lt;/table&amp;gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;
  So if we do a search for the above block in the code, we can easily pull the 
  required information.&lt;/p&gt;
&lt;p&gt;Now, we can follow the following steps to scrape the required information:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt; Retrieve the required page.&lt;/li&gt;
  &lt;li&gt; Look for the consistent part of code that uniquely encloses or identifies 
    the required information. Scrape that block.&lt;/li&gt;
  &lt;li&gt; Pull the required data out.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Following is the code listing:&lt;/p&gt;
&lt;code&gt;&lt;span style="color: #000000"&gt;
&amp;lt;html&amp;gt;
&lt;br /&gt;&amp;lt;head&amp;gt;
&lt;br /&gt;&amp;lt;title&amp;gt;Google&amp;nbsp;Result&amp;nbsp;Scraper&amp;lt;/title&amp;gt;
&lt;br /&gt;&amp;lt;/head&amp;gt;
&lt;br /&gt;
&lt;br /&gt;&amp;lt;body&amp;gt;
&lt;br /&gt;&amp;lt;p&amp;nbsp;align="center"&amp;nbsp;style="font-size:500%"&amp;gt;&amp;lt;font&amp;nbsp;color="#0000FF"&amp;gt;G&amp;lt;/font&amp;gt;&amp;lt;font&amp;nbsp;color="#FF0000"&amp;gt;o&amp;lt;/font&amp;gt;&amp;lt;font&amp;nbsp;color="#FFFF00"&amp;gt;o&amp;lt;/font&amp;gt;&amp;lt;font&amp;nbsp;color="#0000FF"&amp;gt;g&amp;lt;/font&amp;gt;&amp;lt;font&amp;nbsp;color="#00FF00"&amp;gt;l&amp;lt;/font&amp;gt;&amp;lt;font&amp;nbsp;color="#FF0000"&amp;gt;e&amp;lt;/font&amp;gt;&amp;nbsp;

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;font&amp;nbsp;size="2"&amp;gt;&amp;lt;br&amp;nbsp;/&amp;gt;Result&amp;nbsp;Scraper&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;
&lt;br /&gt;
&lt;br /&gt;&lt;span style="color: #0000BB"&gt;&amp;lt;?php
&lt;br /&gt;$s&lt;/span&gt;&lt;span style="color: #007700"&gt;=&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$_GET&lt;/span&gt;&lt;span style="color: #007700"&gt;[&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'s'&lt;/span&gt;&lt;span style="color: #007700"&gt;];

&lt;br /&gt;
&lt;br /&gt;if(isset(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$s&lt;/span&gt;&lt;span style="color: #007700"&gt;))
&lt;br /&gt;{
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #FF8000"&gt;//*******F&amp;nbsp;I&amp;nbsp;R&amp;nbsp;S&amp;nbsp;T&amp;nbsp;&amp;nbsp;&amp;nbsp;P&amp;nbsp;A&amp;nbsp;R&amp;nbsp;T*********
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//Find&amp;nbsp;the&amp;nbsp;number&amp;nbsp;of&amp;nbsp;pages&amp;nbsp;indexed&amp;nbsp;for&amp;nbsp;the&amp;nbsp;searched&amp;nbsp;term

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//*From&amp;nbsp;previous&amp;nbsp;part
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;echo&amp;nbsp;&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"&amp;lt;p&amp;gt;&amp;lt;i&amp;gt;Search&amp;nbsp;for&amp;nbsp;$s&amp;lt;/i&amp;gt;&amp;lt;/p&amp;gt;"&lt;/span&gt;&lt;span style="color: #007700"&gt;;
&lt;br /&gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$s&lt;/span&gt;&lt;span style="color: #007700"&gt;=&lt;/span&gt;&lt;span style="color: #0000BB"&gt;urlencode&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$s&lt;/span&gt;&lt;span style="color: #007700"&gt;);

&lt;br /&gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$main_data&lt;/span&gt;&lt;span style="color: #007700"&gt;=&lt;/span&gt;&lt;span style="color: #0000BB"&gt;file_get_contents&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"http://www.google.com/search?hl=en&amp;amp;q="&lt;/span&gt;&lt;span style="color: #007700"&gt;.&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$s&lt;/span&gt;&lt;span style="color: #007700"&gt;.&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"&amp;amp;btnG=Google+Search"&lt;/span&gt;&lt;span style="color: #007700"&gt;);
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #FF8000"&gt;//strip&amp;nbsp;off&amp;nbsp;HTML

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$data&lt;/span&gt;&lt;span style="color: #007700"&gt;=&lt;/span&gt;&lt;span style="color: #0000BB"&gt;strip_tags&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$main_data&lt;/span&gt;&lt;span style="color: #007700"&gt;);
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #FF8000"&gt;//now&amp;nbsp;$data&amp;nbsp;only&amp;nbsp;has&amp;nbsp;text&amp;nbsp;NO&amp;nbsp;HTML
&lt;br /&gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//these&amp;nbsp;have&amp;nbsp;to&amp;nbsp;ound&amp;nbsp;out&amp;nbsp;in&amp;nbsp;the&amp;nbsp;fetched&amp;nbsp;data

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$find&lt;/span&gt;&lt;span style="color: #007700"&gt;=&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'Results&amp;nbsp;1&amp;nbsp;-&amp;nbsp;10&amp;nbsp;of&amp;nbsp;about&amp;nbsp;'&lt;/span&gt;&lt;span style="color: #007700"&gt;;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$find2&lt;/span&gt;&lt;span style="color: #007700"&gt;=&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'&amp;nbsp;for'&lt;/span&gt;&lt;span style="color: #007700"&gt;;
&lt;br /&gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #FF8000"&gt;//have&amp;nbsp;text&amp;nbsp;beginning&amp;nbsp;from&amp;nbsp;$find

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$data&lt;/span&gt;&lt;span style="color: #007700"&gt;=&lt;/span&gt;&lt;span style="color: #0000BB"&gt;strstr&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$data&lt;/span&gt;&lt;span style="color: #007700"&gt;,&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$find&lt;/span&gt;&lt;span style="color: #007700"&gt;);
&lt;br /&gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #FF8000"&gt;//find&amp;nbsp;position&amp;nbsp;of&amp;nbsp;$find2
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//there&amp;nbsp;might&amp;nbsp;be&amp;nbsp;many&amp;nbsp;occurence

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//but&amp;nbsp;it'd&amp;nbsp;give&amp;nbsp;position&amp;nbsp;of&amp;nbsp;the&amp;nbsp;first&amp;nbsp;one,&amp;nbsp;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//which&amp;nbsp;is&amp;nbsp;what&amp;nbsp;we&amp;nbsp;want,&amp;nbsp;anyway
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$pos&lt;/span&gt;&lt;span style="color: #007700"&gt;=&lt;/span&gt;&lt;span style="color: #0000BB"&gt;strpos&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$data&lt;/span&gt;&lt;span style="color: #007700"&gt;,&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$find2&lt;/span&gt;&lt;span style="color: #007700"&gt;);

&lt;br /&gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #FF8000"&gt;//take&amp;nbsp;substring&amp;nbsp;out,&amp;nbsp;which'd&amp;nbsp;be&amp;nbsp;the&amp;nbsp;number&amp;nbsp;we&amp;nbsp;want
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$search_number&lt;/span&gt;&lt;span style="color: #007700"&gt;=&lt;/span&gt;&lt;span style="color: #0000BB"&gt;substr&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$data&lt;/span&gt;&lt;span style="color: #007700"&gt;,&lt;/span&gt;&lt;span style="color: #0000BB"&gt;strlen&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$find&lt;/span&gt;&lt;span style="color: #007700"&gt;),&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$pos&lt;/span&gt;&lt;span style="color: #007700"&gt;-&lt;/span&gt;&lt;span style="color: #0000BB"&gt;strlen&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$find&lt;/span&gt;&lt;span style="color: #007700"&gt;));

&lt;br /&gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;echo&amp;nbsp;&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"Pages&amp;nbsp;Indexed:&amp;nbsp;$search_number"&lt;/span&gt;&lt;span style="color: #007700"&gt;;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #FF8000"&gt;//********S&amp;nbsp;E&amp;nbsp;C&amp;nbsp;O&amp;nbsp;N&amp;nbsp;D&amp;nbsp;&amp;nbsp;&amp;nbsp;P&amp;nbsp;A&amp;nbsp;R&amp;nbsp;T*******

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//Find&amp;nbsp;related&amp;nbsp;searches
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;echo&amp;nbsp;&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"&amp;lt;h3&amp;gt;Related&amp;nbsp;Keywords&amp;lt;/h3&amp;gt;"&lt;/span&gt;&lt;span style="color: #007700"&gt;;
&lt;br /&gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #FF8000"&gt;//these&amp;nbsp;have&amp;nbsp;to&amp;nbsp;found&amp;nbsp;out&amp;nbsp;in&amp;nbsp;the&amp;nbsp;fetched&amp;nbsp;data

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$find&lt;/span&gt;&lt;span style="color: #007700"&gt;=&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'&amp;lt;h2&amp;nbsp;class=r&amp;gt;Searches&amp;nbsp;related&amp;nbsp;to:'&lt;/span&gt;&lt;span style="color: #007700"&gt;;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$find2&lt;/span&gt;&lt;span style="color: #007700"&gt;=&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'&amp;lt;/table&amp;gt;'&lt;/span&gt;&lt;span style="color: #007700"&gt;;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$find3&lt;/span&gt;&lt;span style="color: #007700"&gt;=&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'&amp;lt;table&amp;nbsp;border=0'&lt;/span&gt;&lt;span style="color: #007700"&gt;;

&lt;br /&gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #FF8000"&gt;//have&amp;nbsp;text&amp;nbsp;beginning&amp;nbsp;from&amp;nbsp;$find
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$data&lt;/span&gt;&lt;span style="color: #007700"&gt;=&lt;/span&gt;&lt;span style="color: #0000BB"&gt;strstr&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$main_data&lt;/span&gt;&lt;span style="color: #007700"&gt;,&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$find&lt;/span&gt;&lt;span style="color: #007700"&gt;);
&lt;br /&gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #FF8000"&gt;//find&amp;nbsp;position&amp;nbsp;of&amp;nbsp;$find2

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//there&amp;nbsp;might&amp;nbsp;be&amp;nbsp;many&amp;nbsp;occurence
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//but&amp;nbsp;it'd&amp;nbsp;give&amp;nbsp;position&amp;nbsp;of&amp;nbsp;the&amp;nbsp;first&amp;nbsp;one,&amp;nbsp;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//which&amp;nbsp;is&amp;nbsp;what&amp;nbsp;we&amp;nbsp;want,&amp;nbsp;anyway

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$pos&lt;/span&gt;&lt;span style="color: #007700"&gt;=&lt;/span&gt;&lt;span style="color: #0000BB"&gt;strpos&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$data&lt;/span&gt;&lt;span style="color: #007700"&gt;,&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$find2&lt;/span&gt;&lt;span style="color: #007700"&gt;);
&lt;br /&gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #FF8000"&gt;//take&amp;nbsp;substring&amp;nbsp;out,&amp;nbsp;this&amp;nbsp;is&amp;nbsp;the&amp;nbsp;block&amp;nbsp;of&amp;nbsp;data

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//that&amp;nbsp;we'd&amp;nbsp;fetch&amp;nbsp;required&amp;nbsp;information&amp;nbsp;off&amp;nbsp;of.
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$related_search_block&lt;/span&gt;&lt;span style="color: #007700"&gt;=&lt;/span&gt;&lt;span style="color: #0000BB"&gt;substr&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$data&lt;/span&gt;&lt;span style="color: #007700"&gt;,&lt;/span&gt;&lt;span style="color: #0000BB"&gt;strlen&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$find&lt;/span&gt;&lt;span style="color: #007700"&gt;),&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$pos&lt;/span&gt;&lt;span style="color: #007700"&gt;-&lt;/span&gt;&lt;span style="color: #0000BB"&gt;strlen&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$find&lt;/span&gt;&lt;span style="color: #007700"&gt;));

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #FF8000"&gt;//pull&amp;nbsp;out&amp;nbsp;the&amp;nbsp;required&amp;nbsp;data,&amp;nbsp;stripping&amp;nbsp;off&amp;nbsp;"Searches&amp;nbsp;related&amp;nbsp;to.."
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$related_searches&lt;/span&gt;&lt;span style="color: #007700"&gt;=&lt;/span&gt;&lt;span style="color: #0000BB"&gt;strstr&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$related_search_block&lt;/span&gt;&lt;span style="color: #007700"&gt;,&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$find3&lt;/span&gt;&lt;span style="color: #007700"&gt;);

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #FF8000"&gt;//now&amp;nbsp;we&amp;nbsp;only&amp;nbsp;have&amp;nbsp;the&amp;nbsp;keywords,&amp;nbsp;of&amp;nbsp;course&amp;nbsp;formatted&amp;nbsp;as&amp;nbsp;is
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//with&amp;nbsp;tables
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//strip&amp;nbsp;off&amp;nbsp;HTML,&amp;nbsp;therefore&amp;nbsp;taking&amp;nbsp;off&amp;nbsp;table&amp;nbsp;and&amp;nbsp;various

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//other&amp;nbsp;formattings
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$related_searches&lt;/span&gt;&lt;span style="color: #007700"&gt;=&lt;/span&gt;&lt;span style="color: #0000BB"&gt;strip_tags&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$related_searches&lt;/span&gt;&lt;span style="color: #007700"&gt;);
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #FF8000"&gt;//now&amp;nbsp;we&amp;nbsp;have&amp;nbsp;the&amp;nbsp;keywords&amp;nbsp;(plain&amp;nbsp;text)&amp;nbsp;sepearted&amp;nbsp;with&amp;nbsp;

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//each&amp;nbsp;other&amp;nbsp;using&amp;nbsp;"&amp;amp;nbsp;'
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//explode&amp;nbsp;it
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$keywords&lt;/span&gt;&lt;span style="color: #007700"&gt;=&lt;/span&gt;&lt;span style="color: #0000BB"&gt;explode&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'&amp;amp;nbsp;'&lt;/span&gt;&lt;span style="color: #007700"&gt;,&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$related_searches&lt;/span&gt;&lt;span style="color: #007700"&gt;);

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #FF8000"&gt;//now&amp;nbsp;we&amp;nbsp;a&amp;nbsp;nice&amp;nbsp;array&amp;nbsp;having&amp;nbsp;all&amp;nbsp;the&amp;nbsp;keywords
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//print&amp;nbsp;the&amp;nbsp;keywords
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//nicely&amp;nbsp;formatted&amp;nbsp;using&amp;nbsp;&amp;lt;ol&amp;gt;&amp;nbsp;(ordered&amp;nbsp;list)

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;echo&amp;nbsp;&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"&amp;lt;ol&amp;gt;"&lt;/span&gt;&lt;span style="color: #007700"&gt;;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;foreach(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$keywords&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;as&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$keyword&lt;/span&gt;&lt;span style="color: #007700"&gt;)
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$keyword&lt;/span&gt;&lt;span style="color: #007700"&gt;!=&lt;/span&gt;&lt;span style="color: #DD0000"&gt;''&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;&amp;amp;&amp;amp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$keyword&lt;/span&gt;&lt;span style="color: #007700"&gt;!=&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'&amp;nbsp;'&lt;/span&gt;&lt;span style="color: #007700"&gt;)

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;echo&amp;nbsp;&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"&amp;lt;li&amp;gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$keyword
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/li&amp;gt;"&lt;/span&gt;&lt;span style="color: #007700"&gt;;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;echo&amp;nbsp;&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"&amp;lt;/ol&amp;gt;"&lt;/span&gt;&lt;span style="color: #007700"&gt;;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;br /&gt;}
&lt;br /&gt;else

&lt;br /&gt;{
&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;?&amp;gt;
&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;&amp;lt;form&amp;nbsp;name="form1"&amp;nbsp;id="form1"&amp;nbsp;method="get"&amp;nbsp;action=""&amp;gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;div&amp;nbsp;align="center"&amp;gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;p&amp;gt;&amp;nbsp;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;input&amp;nbsp;name="s"&amp;nbsp;type="text"&amp;nbsp;id="s"&amp;nbsp;size="50"&amp;nbsp;/&amp;gt;

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;input&amp;nbsp;type="submit"&amp;nbsp;name="Submit"&amp;nbsp;value="Find&amp;nbsp;Related&amp;nbsp;Keywords"&amp;nbsp;/&amp;gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/p&amp;gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;/div&amp;gt;
&lt;br /&gt;&amp;lt;/form&amp;gt;
&lt;br /&gt;&amp;lt;p&amp;gt;&amp;amp;nbsp;&amp;lt;/p&amp;gt;

&lt;br /&gt;&amp;lt;p&amp;gt;&amp;amp;nbsp;&amp;lt;/p&amp;gt;
&lt;br /&gt;&amp;lt;p&amp;gt;&amp;amp;nbsp;&amp;lt;/p&amp;gt;
&lt;br /&gt;&amp;lt;p&amp;gt;&amp;amp;nbsp;&amp;lt;/p&amp;gt;
&lt;br /&gt;&amp;lt;p&amp;gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span style="color: #0000BB"&gt;&amp;lt;?php
&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #007700"&gt;}
&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;?&amp;gt;

&lt;br /&gt;&lt;/span&gt;&amp;lt;/p&amp;gt;
&lt;br /&gt;&amp;lt;p&amp;nbsp;align="right"&amp;gt;&amp;lt;font&amp;nbsp;size="2"&amp;gt;by&amp;nbsp;&amp;lt;a&amp;nbsp;href="http://learning-computer-programming.blogspot.com/"&amp;gt;Learning&amp;nbsp;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;Computer&amp;nbsp;Programming&amp;lt;/a&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;

&lt;br /&gt;&amp;lt;/body&amp;gt;
&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;
&lt;p&gt;
  Although this script is not very useful as it is (after all it&amp;#8217;s meant 
  for learning purpose) you can make it more useful by extending it. one thing 
  that&amp;#8217;d be nice is to hav it search for related keywords and again take 
  each keyword as a base for further searches. This way it&amp;#8217;d be able to 
  supply you with many keywords related to the one entered. Best thing is, the 
  keywords will be Googly Related!&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Previous Posts:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/06/basic-web-scraping-scraping-google.html"&gt;Web 
      Scraping: Pulling Out Data From Google Search Results&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/06/creating-simple-html-form-validation.html"&gt;Creating 
      a Simple Form Validation Script Using JavaScript&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/06/creating-simple-html-form-validation.html"&gt;Deigning 
      a Simple HTML Menu-Bar Using CSS &lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/06/blogger-method-to-add-link-to-this-post.html"&gt;Blogger: 
      Method to Add &amp;#8216;Link to This Post&amp;#8217; Widget on Your Posts &lt;/a&gt; 
    &lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/05/new-working-method-of-making-blogger.html"&gt;New 
      Working Method of Making Blogger Title Tags SEO Friendly&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/33629562-8573334290002368620?l=learning-computer-programming.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TiGWE/~4/JpnT1enI8t4" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://learning-computer-programming.blogspot.com/feeds/8573334290002368620/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://learning-computer-programming.blogspot.com/2008/08/web-scraping-gathering-related-searches.html#comment-form" title="4 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/33629562/posts/default/8573334290002368620?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/33629562/posts/default/8573334290002368620?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/TiGWE/~3/JpnT1enI8t4/web-scraping-gathering-related-searches.html" title="Web Scraping: Gathering &quot;Related Searches&quot; Keyword Data From Google Search Results" /><author><name>Arvind Gupta</name><uri>http://www.blogger.com/profile/17199066124402939022</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="23" height="32" src="http://one.arvind.googlepages.com/arvind_gupta_photo.jpg" /></author><thr:total>4</thr:total><feedburner:origLink>http://learning-computer-programming.blogspot.com/2008/08/web-scraping-gathering-related-searches.html</feedburner:origLink></entry><entry gd:etag="W/&quot;Ck4ERX87eCp7ImA9WxdUFE0.&quot;"><id>tag:blogger.com,1999:blog-33629562.post-2036353860421367180</id><published>2008-07-30T12:16:00.000+05:30</published><updated>2008-07-30T12:25:04.100+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-07-30T12:25:04.100+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Web" /><category scheme="http://www.blogger.com/atom/ns#" term="PHP" /><category scheme="http://www.blogger.com/atom/ns#" term="Example Programs" /><category scheme="http://www.blogger.com/atom/ns#" term="Useful Scripts" /><category scheme="http://www.blogger.com/atom/ns#" term="Complete Script" /><category scheme="http://www.blogger.com/atom/ns#" term="HTML" /><category scheme="http://www.blogger.com/atom/ns#" term="Searching" /><title>Performing Simple String Search Using PHP and MySQL</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/-N4fgWfvdSRjdSljEAhEC93Ic4M/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/-N4fgWfvdSRjdSljEAhEC93Ic4M/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/-N4fgWfvdSRjdSljEAhEC93Ic4M/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/-N4fgWfvdSRjdSljEAhEC93Ic4M/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p align="center"&gt;&lt;img src="http://one.arvind.googlepages.com/ph_book_w_search02.gif" alt="Performing Simple String Search Using PHP and MySQL " width="222" height="177" /&gt;&lt;/p&gt;
&lt;p&gt;Here it is, a post after so long!&lt;/p&gt;
&lt;p&gt;We see &amp;#8220;Search&amp;#8221; feature on almost all websites. Some employ third-party 
  tools (like Google Custom Search) while others, mostly CMS based websites, have 
  their own Search feature. The question now is, How do Search Feature Work? Answer 
  is, it (almost always) uses MySQL (or database server&amp;#8217;s capability. You 
  all might be knowing that CMSs always store information in databases. So if 
  we can search that we can very well search the whole site!&lt;/p&gt;
&lt;p&gt;So today we&amp;#8217;re going to employ the feature of MySQL to perform simple 
  searching. As an example we&amp;#8217;ll be creating an Online Phonebook to illustrate 
  this.&lt;/p&gt;
&lt;p&gt;&lt;font size="4"&gt;MySQL&amp;#8217;s Simple Search (String Matching) Query&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;select [coulumn1] from [table] where [column2] like &amp;#8216;$var%&amp;#8217;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;(For some of the basic SQL queries refer to &lt;a href="http://learning-computer-programming.blogspot.com/2008/05/about-mysql-databases-and-sql-commands.html"&gt;MySQL 
  Commands&lt;/a&gt;) &lt;/p&gt;
&lt;p&gt;we&amp;#8217;ll take a simple example to illustrate the above query. Suppose we 
  have a table with the following rows and columns:&lt;/p&gt;
&lt;table width="80%" border="1" align="center" cellpadding="0" cellspacing="0"&gt;
  &lt;tr&gt;
    &lt;td width="7%"&gt;&lt;strong&gt;id&lt;/strong&gt;&lt;/td&gt;
    &lt;td width="26%"&gt;&lt;strong&gt;column-1&lt;/strong&gt;&lt;/td&gt;
    &lt;td width="67%"&gt; &lt;strong&gt;column-2&lt;/strong&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;1&lt;/td&gt;
    &lt;td&gt;cat&lt;/td&gt;
    &lt;td&gt;there is a cat&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;2&lt;/td&gt;
    &lt;td&gt;dog&lt;/td&gt;
    &lt;td&gt;there is a dog&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;3&lt;/td&gt;
    &lt;td&gt;can&lt;/td&gt;
    &lt;td&gt;there is a cold drink can&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;4&lt;/td&gt;
    &lt;td&gt;campus&lt;/td&gt;
    &lt;td&gt; i like my college campus&lt;/td&gt;
  &lt;/tr&gt;
&lt;/table&gt;
&lt;p&gt;Now look closely what different queries will return:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&lt;strong&gt;&lt;font size="5"&gt;1.&lt;/font&gt; select * from table where column-1 like 
  'ca%'&lt;/strong&gt;&lt;/code&gt;&lt;/p&gt;
&lt;table width="80%" border="1" align="center" cellpadding="0" cellspacing="0"&gt;
  &lt;tr&gt; 
    &lt;td width="7%"&gt;&lt;strong&gt;id&lt;/strong&gt;&lt;/td&gt;
    &lt;td width="26%"&gt;&lt;strong&gt;column-1&lt;/strong&gt;&lt;/td&gt;
    &lt;td width="67%"&gt; &lt;strong&gt;column-2&lt;/strong&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt; 
    &lt;td&gt;1&lt;/td&gt;
    &lt;td&gt;cat&lt;/td&gt;
    &lt;td&gt;there is a cat&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt; 
    &lt;td&gt;3&lt;/td&gt;
    &lt;td&gt;can&lt;/td&gt;
    &lt;td&gt;there is a cold drink can&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt; 
    &lt;td&gt;4&lt;/td&gt;
    &lt;td&gt;campus&lt;/td&gt;
    &lt;td&gt; i like my college campus&lt;/td&gt;
  &lt;/tr&gt;
&lt;/table&gt;
&lt;p&gt;&lt;code&gt;&lt;strong&gt;&lt;font size="5"&gt;2.&lt;/font&gt; select * from table where column-1 like 
  'cam%'&lt;/strong&gt;&lt;/code&gt;&lt;/p&gt;
&lt;table width="80%" border="1" align="center" cellpadding="0" cellspacing="0"&gt;
  &lt;tr&gt; 
    &lt;td width="7%"&gt;&lt;strong&gt;id&lt;/strong&gt;&lt;/td&gt;
    &lt;td width="26%"&gt;&lt;strong&gt;column-1&lt;/strong&gt;&lt;/td&gt;
    &lt;td width="67%"&gt; &lt;strong&gt;column-2&lt;/strong&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt; 
    &lt;td&gt;4&lt;/td&gt;
    &lt;td&gt;campus&lt;/td&gt;
    &lt;td&gt; i like my college campus&lt;/td&gt;
  &lt;/tr&gt;
&lt;/table&gt;
&lt;p&gt;&lt;code&gt;&lt;strong&gt;&lt;font size="5"&gt;3.&lt;/font&gt; select * from table where column-1 like 
  'd%'&lt;/strong&gt;&lt;/code&gt;&lt;/p&gt;
&lt;table width="80%" border="1" align="center" cellpadding="0" cellspacing="0"&gt;
  &lt;tr&gt; 
    &lt;td width="7%"&gt;&lt;strong&gt;id&lt;/strong&gt;&lt;/td&gt;
    &lt;td width="26%"&gt;&lt;strong&gt;column-1&lt;/strong&gt;&lt;/td&gt;
    &lt;td width="67%"&gt; &lt;strong&gt;column-2&lt;/strong&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt; 
    &lt;td&gt;2&lt;/td&gt;
    &lt;td&gt;dog&lt;/td&gt;
    &lt;td&gt;there is a dog&lt;/td&gt;
  &lt;/tr&gt;
&lt;/table&gt;
&lt;p&gt;&lt;code&gt;&lt;strong&gt;&lt;font size="5"&gt;4.&lt;/font&gt; select * from table where column-2 like 
  'cat%'&lt;/strong&gt;&lt;/code&gt;&lt;/p&gt;
&lt;table width="80%" border="1" align="center" cellpadding="0" cellspacing="0"&gt;
  &lt;tr&gt; 
    &lt;td width="7%"&gt;&lt;strong&gt;id&lt;/strong&gt;&lt;/td&gt;
    &lt;td width="26%"&gt;&lt;strong&gt;column-1&lt;/strong&gt;&lt;/td&gt;
    &lt;td width="67%"&gt; &lt;strong&gt;column-2&lt;/strong&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt; 
    &lt;td&gt;NULL&lt;/td&gt;
    &lt;td&gt;NULL&lt;/td&gt;
    &lt;td&gt;NULL&lt;/td&gt;
  &lt;/tr&gt;
&lt;/table&gt;
&lt;p&gt;&lt;code&gt;&lt;strong&gt;&lt;font size="5"&gt;5.&lt;/font&gt; select * from table where column-2 like 
  'there%'&lt;/strong&gt;&lt;/code&gt;&lt;/p&gt;
&lt;table width="80%" border="1" align="center" cellpadding="0" cellspacing="0"&gt;
  &lt;tr&gt; 
    &lt;td width="7%"&gt;&lt;strong&gt;id&lt;/strong&gt;&lt;/td&gt;
    &lt;td width="26%"&gt;&lt;strong&gt;column-1&lt;/strong&gt;&lt;/td&gt;
    &lt;td width="67%"&gt; &lt;strong&gt;column-2&lt;/strong&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt; 
    &lt;td&gt;1&lt;/td&gt;
    &lt;td&gt;cat&lt;/td&gt;
    &lt;td&gt;there is a cat&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt; 
    &lt;td&gt;2&lt;/td&gt;
    &lt;td&gt;dog&lt;/td&gt;
    &lt;td&gt;there is a dog&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt; 
    &lt;td&gt;3&lt;/td&gt;
    &lt;td&gt;can&lt;/td&gt;
    &lt;td&gt;there is a cold drink can&lt;/td&gt;
  &lt;/tr&gt;
&lt;/table&gt;
&lt;p&gt; At this time it is worth noting that, while we can use this method to search 
  for strings whose initial characters (words) are known but impossible to search 
  for words within a string (like in query no. 4).&lt;/p&gt;
&lt;p&gt;That&amp;#8217;s it, all we need to perform simple search is the above mentioned 
  query!&lt;/p&gt;
&lt;p&gt;Below the source code for an Online Phone Book is given, it&amp;#8217;d store phone 
  numbers along with names. Its search feature will search names column, hence 
  you can search for phone numbers by name.&lt;/p&gt;
&lt;code&gt;&lt;span style="color: #000000"&gt;
&lt;span style="color: #0000BB"&gt;&amp;lt;?php
&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #FF9900"&gt;/*Script:&amp;nbsp;Onilne&amp;nbsp;Phone&amp;nbsp;Book&amp;nbsp;with&amp;nbsp;Search&amp;nbsp;Facility
&lt;br /&gt;Date:&amp;nbsp;29-July-08
&lt;br /&gt;Copyright&amp;nbsp;2008&amp;nbsp;Arvind&amp;nbsp;Gupta
&lt;br /&gt;http://learning-computer-programming.blogspot.com/
&lt;br /&gt;

&lt;br /&gt;You&amp;nbsp;are&amp;nbsp;free&amp;nbsp;to&amp;nbsp;modify,&amp;nbsp;change,&amp;nbsp;publish&amp;nbsp;or&amp;nbsp;do&amp;nbsp;whatever&amp;nbsp;with&amp;nbsp;this&amp;nbsp;script
&lt;br /&gt;as&amp;nbsp;long&amp;nbsp;as&amp;nbsp;this&amp;nbsp;note&amp;nbsp;is&amp;nbsp;intact.&amp;nbsp;Thank&amp;nbsp;You!*/

&lt;br /&gt;
&lt;br /&gt;//connect&amp;nbsp;to&amp;nbsp;MySQL
&lt;br /&gt;//provide&amp;nbsp;your&amp;nbsp;'username'&amp;nbsp;and&amp;nbsp;'pass'
&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$db&lt;/span&gt;&lt;span style="color: #007700"&gt;=new&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;mysqli&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'localhost'&lt;/span&gt;&lt;span style="color: #007700"&gt;,&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'-USER-'&lt;/span&gt;&lt;span style="color: #007700"&gt;,&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'-PASS-'&lt;/span&gt;&lt;span style="color: #007700"&gt;);

&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #FF9900"&gt;//if&amp;nbsp;'save'&amp;nbsp;button&amp;nbsp;was&amp;nbsp;pressed
&lt;br /&gt;//user&amp;nbsp;wants&amp;nbsp;to&amp;nbsp;store&amp;nbsp;phone&amp;nbsp;number
&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #007700"&gt;if(isset(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$_POST&lt;/span&gt;&lt;span style="color: #007700"&gt;[&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'save'&lt;/span&gt;&lt;span style="color: #007700"&gt;]))
&lt;br /&gt;{

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$name&lt;/span&gt;&lt;span style="color: #007700"&gt;=&lt;/span&gt;&lt;span style="color: #0000BB"&gt;trim&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$_POST&lt;/span&gt;&lt;span style="color: #007700"&gt;[&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'name'&lt;/span&gt;&lt;span style="color: #007700"&gt;]);
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$phno&lt;/span&gt;&lt;span style="color: #007700"&gt;=&lt;/span&gt;&lt;span style="color: #0000BB"&gt;trim&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$_POST&lt;/span&gt;&lt;span style="color: #007700"&gt;[&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'phno'&lt;/span&gt;&lt;span style="color: #007700"&gt;]);
&lt;br /&gt;

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #FF9900"&gt;//if&amp;nbsp;data&amp;nbsp;supplied&amp;nbsp;are&amp;nbsp;not&amp;nbsp;empty
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;if(!&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$name&lt;/span&gt;&lt;span style="color: #007700"&gt;==&lt;/span&gt;&lt;span style="color: #DD0000"&gt;''&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;||&amp;nbsp;!&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$phno&lt;/span&gt;&lt;span style="color: #007700"&gt;==&lt;/span&gt;&lt;span style="color: #DD0000"&gt;''&lt;/span&gt;&lt;span style="color: #007700"&gt;)
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #FF9900"&gt;//if&amp;nbsp;this&amp;nbsp;is&amp;nbsp;the&amp;nbsp;first&amp;nbsp;time
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//and&amp;nbsp;database&amp;nbsp;is&amp;nbsp;not&amp;nbsp;craeted
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;if(!&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$db&lt;/span&gt;&lt;span style="color: #007700"&gt;-&amp;gt;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;select_db&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'one'&lt;/span&gt;&lt;span style="color: #007700"&gt;))

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #FF9900"&gt;//create&amp;nbsp;the&amp;nbsp;database
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$db&lt;/span&gt;&lt;span style="color: #007700"&gt;-&amp;gt;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;query&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'create&amp;nbsp;database&amp;nbsp;one'&lt;/span&gt;&lt;span style="color: #007700"&gt;);
&lt;br /&gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #FF9900"&gt;//select&amp;nbsp;the&amp;nbsp;databasw&amp;nbsp;to&amp;nbsp;work&amp;nbsp;with

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$db&lt;/span&gt;&lt;span style="color: #007700"&gt;-&amp;gt;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;select_db&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'one'&lt;/span&gt;&lt;span style="color: #007700"&gt;);
&lt;br /&gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #FF9900"&gt;//if&amp;nbsp;table&amp;nbsp;is&amp;nbsp;not&amp;nbsp;craeted,&amp;nbsp;craete&amp;nbsp;it
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;if(!&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$db&lt;/span&gt;&lt;span style="color: #007700"&gt;-&amp;gt;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;query&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'select&amp;nbsp;*&amp;nbsp;from&amp;nbsp;phno'&lt;/span&gt;&lt;span style="color: #007700"&gt;))

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$db&lt;/span&gt;&lt;span style="color: #007700"&gt;-&amp;gt;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;query&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'create&amp;nbsp;table&amp;nbsp;phno(id&amp;nbsp;int&amp;nbsp;auto_increment&amp;nbsp;primary&amp;nbsp;key,&amp;nbsp;name&amp;nbsp;varchar(50),&amp;nbsp;phnum&amp;nbsp;varchar(20))'&lt;/span&gt;&lt;span style="color: #007700"&gt;);
&lt;br /&gt;

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #FF9900"&gt;//ready&amp;nbsp;to&amp;nbsp;insert&amp;nbsp;data
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$db&lt;/span&gt;&lt;span style="color: #007700"&gt;-&amp;gt;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;query&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"insert&amp;nbsp;into&amp;nbsp;phno&amp;nbsp;(name,&amp;nbsp;phnum)&amp;nbsp;values&amp;nbsp;('$name',&amp;nbsp;'$phno')"&lt;/span&gt;&lt;span style="color: #007700"&gt;);

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&lt;br /&gt;}
&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #FF9900"&gt;//show&amp;nbsp;the&amp;nbsp;form
&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;?&amp;gt;
&lt;br /&gt;&lt;/span&gt;&amp;lt;html&amp;gt;
&lt;br /&gt;&amp;lt;head&amp;gt;
&lt;br /&gt;&amp;lt;title&amp;gt;My&amp;nbsp;Phone&amp;nbsp;Book&amp;lt;/title&amp;gt;

&lt;br /&gt;&amp;lt;/head&amp;gt;
&lt;br /&gt;
&lt;br /&gt;&amp;lt;body&amp;gt;
&lt;br /&gt;&amp;lt;h1&amp;gt;My&amp;nbsp;Phone&amp;nbsp;Book&amp;lt;/h1&amp;gt;
&lt;br /&gt;&amp;lt;h2&amp;nbsp;style="background:&amp;nbsp;#000;&amp;nbsp;color:&amp;nbsp;#fff;"&amp;gt;Store&amp;nbsp;New&amp;nbsp;Phone&amp;nbsp;Number&amp;lt;/h2&amp;gt;

&lt;br /&gt;&amp;lt;form&amp;nbsp;name="form2"&amp;nbsp;method="get"&amp;nbsp;action=""&amp;gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;p&amp;nbsp;style="background:&amp;nbsp;#000;&amp;nbsp;color:&amp;nbsp;#fff;"&amp;gt;&amp;lt;b&amp;gt;Search:&amp;lt;/b&amp;gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;input&amp;nbsp;name="search"&amp;nbsp;type="text"&amp;nbsp;id="search"&amp;gt;

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;input&amp;nbsp;name="searchb"&amp;nbsp;type="submit"&amp;nbsp;id="searchb"&amp;nbsp;value="Search"&amp;gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;/p&amp;gt;
&lt;br /&gt;&amp;lt;/form&amp;gt;
&lt;br /&gt;&amp;lt;p&amp;gt;&amp;lt;/p&amp;gt;
&lt;br /&gt;&amp;lt;form&amp;nbsp;name="form1"&amp;nbsp;id="form1"&amp;nbsp;method="post"&amp;nbsp;action=""&amp;gt;

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;table&amp;nbsp;width="250"&amp;nbsp;border="0"&amp;nbsp;cellspacing="0"&amp;nbsp;cellpadding="0"&amp;gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;tr&amp;gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;td&amp;nbsp;width="83"&amp;gt;Name&amp;lt;/td&amp;gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;td&amp;nbsp;width="417"&amp;gt;&amp;lt;input&amp;nbsp;name="name"&amp;nbsp;type="text"&amp;nbsp;id="name"&amp;nbsp;/&amp;gt;&amp;lt;/td&amp;gt;

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/tr&amp;gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;tr&amp;gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;td&amp;gt;Ph.&amp;nbsp;No.&amp;lt;/td&amp;gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;td&amp;gt;&amp;lt;input&amp;nbsp;name="phno"&amp;nbsp;type="text"&amp;nbsp;id="phno"&amp;nbsp;value=""&amp;gt;&amp;lt;/td&amp;gt;

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/tr&amp;gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;tr&amp;gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;td&amp;gt;&amp;lt;input&amp;nbsp;name="save"&amp;nbsp;type="submit"&amp;nbsp;id="save"&amp;nbsp;value="Save"&amp;nbsp;/&amp;gt;&amp;lt;/td&amp;gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;td&amp;gt;&amp;lt;input&amp;nbsp;type="reset"&amp;nbsp;name="Submit2"&amp;nbsp;value="Reset"&amp;nbsp;/&amp;gt;&amp;lt;/td&amp;gt;

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/tr&amp;gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;/table&amp;gt;
&lt;br /&gt;&amp;lt;/form&amp;gt;
&lt;br /&gt;&amp;lt;h2&amp;nbsp;style="background:&amp;nbsp;#000;&amp;nbsp;color:&amp;nbsp;#fff;"&amp;gt;Previously&amp;nbsp;Stored&amp;lt;/h2&amp;gt;
&lt;br /&gt;&amp;lt;p&amp;gt;ORDER&amp;nbsp;BY:&amp;nbsp;&amp;lt;a&amp;nbsp;href="?order=new"&amp;gt;newest&amp;nbsp;first&amp;nbsp;&amp;lt;/a&amp;gt;|&amp;nbsp;&amp;lt;a&amp;nbsp;href="?order=old"&amp;gt;oldest

&lt;br /&gt;&amp;nbsp;&amp;nbsp;first&amp;lt;/a&amp;gt;&amp;nbsp;|&amp;nbsp;&amp;lt;a&amp;nbsp;href="?order=az"&amp;gt;a-z&amp;lt;/a&amp;gt;&amp;nbsp;|&amp;nbsp;&amp;lt;a&amp;nbsp;href="?order=za"&amp;gt;z-a&amp;lt;/a&amp;gt;&amp;lt;/p&amp;gt;
&lt;br /&gt;&amp;lt;/body&amp;gt;
&lt;br /&gt;&amp;lt;/html&amp;gt;

&lt;br /&gt;&lt;span style="color: #0000BB"&gt;&amp;lt;?php
&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #FF9900"&gt;//----DISPALY&amp;nbsp;PREVIOUSLY&amp;nbsp;STORED&amp;nbsp;PH.&amp;nbsp;NUMBERS----
&lt;br /&gt;
&lt;br /&gt;//create&amp;nbsp;the&amp;nbsp;SQL&amp;nbsp;query&amp;nbsp;as&amp;nbsp;per&amp;nbsp;the&amp;nbsp;action
&lt;br /&gt;//if&amp;nbsp;any&amp;nbsp;ordering&amp;nbsp;is&amp;nbsp;selected

&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$order&lt;/span&gt;&lt;span style="color: #007700"&gt;=&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$_GET&lt;/span&gt;&lt;span style="color: #007700"&gt;[&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'order'&lt;/span&gt;&lt;span style="color: #007700"&gt;];
&lt;br /&gt;if(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$order&lt;/span&gt;&lt;span style="color: #007700"&gt;==&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'new'&lt;/span&gt;&lt;span style="color: #007700"&gt;)
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$query&lt;/span&gt;&lt;span style="color: #007700"&gt;=&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"select&amp;nbsp;*&amp;nbsp;from&amp;nbsp;phno&amp;nbsp;order&amp;nbsp;by&amp;nbsp;id&amp;nbsp;desc"&lt;/span&gt;&lt;span style="color: #007700"&gt;;

&lt;br /&gt;elseif(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$order&lt;/span&gt;&lt;span style="color: #007700"&gt;==&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'old'&lt;/span&gt;&lt;span style="color: #007700"&gt;)
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$query&lt;/span&gt;&lt;span style="color: #007700"&gt;=&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"select&amp;nbsp;*&amp;nbsp;from&amp;nbsp;phno&amp;nbsp;order&amp;nbsp;by&amp;nbsp;id&amp;nbsp;asc"&lt;/span&gt;&lt;span style="color: #007700"&gt;;
&lt;br /&gt;elseif(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$order&lt;/span&gt;&lt;span style="color: #007700"&gt;==&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'az'&lt;/span&gt;&lt;span style="color: #007700"&gt;)

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$query&lt;/span&gt;&lt;span style="color: #007700"&gt;=&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"select&amp;nbsp;*&amp;nbsp;from&amp;nbsp;phno&amp;nbsp;order&amp;nbsp;by&amp;nbsp;name&amp;nbsp;asc"&lt;/span&gt;&lt;span style="color: #007700"&gt;;
&lt;br /&gt;elseif(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$order&lt;/span&gt;&lt;span style="color: #007700"&gt;==&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'za'&lt;/span&gt;&lt;span style="color: #007700"&gt;)
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$query&lt;/span&gt;&lt;span style="color: #007700"&gt;=&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"select&amp;nbsp;*&amp;nbsp;from&amp;nbsp;phno&amp;nbsp;order&amp;nbsp;by&amp;nbsp;name&amp;nbsp;desc"&lt;/span&gt;&lt;span style="color: #007700"&gt;;

&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #FF9900"&gt;//or&amp;nbsp;if&amp;nbsp;user&amp;nbsp;is&amp;nbsp;searching
&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #007700"&gt;elseif(isset(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$_GET&lt;/span&gt;&lt;span style="color: #007700"&gt;[&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'searchb'&lt;/span&gt;&lt;span style="color: #007700"&gt;]))
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$search&lt;/span&gt;&lt;span style="color: #007700"&gt;=&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$_GET&lt;/span&gt;&lt;span style="color: #007700"&gt;[&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'search'&lt;/span&gt;&lt;span style="color: #007700"&gt;];

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$query&lt;/span&gt;&lt;span style="color: #007700"&gt;=&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"select&amp;nbsp;*&amp;nbsp;from&amp;nbsp;phno&amp;nbsp;where&amp;nbsp;name&amp;nbsp;like&amp;nbsp;'$search%'"&lt;/span&gt;&lt;span style="color: #007700"&gt;;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&lt;br /&gt;else
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #FF9900"&gt;//use&amp;nbsp;the&amp;nbsp;default&amp;nbsp;query

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$query&lt;/span&gt;&lt;span style="color: #007700"&gt;=&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"select&amp;nbsp;*&amp;nbsp;from&amp;nbsp;phno"&lt;/span&gt;&lt;span style="color: #007700"&gt;;
&lt;br /&gt;
&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #FF9900"&gt;//if&amp;nbsp;database&amp;nbsp;does&amp;nbsp;not&amp;nbsp;exits
&lt;br /&gt;//first&amp;nbsp;time&amp;nbsp;operation
&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #007700"&gt;if(!&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$db&lt;/span&gt;&lt;span style="color: #007700"&gt;-&amp;gt;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;select_db&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'one'&lt;/span&gt;&lt;span style="color: #007700"&gt;))

&lt;br /&gt;{
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;echo&amp;nbsp;&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"&amp;lt;p&amp;gt;&amp;lt;i&amp;gt;NONE&amp;lt;/i&amp;gt;&amp;lt;/p&amp;gt;"&lt;/span&gt;&lt;span style="color: #007700"&gt;;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;exit;
&lt;br /&gt;}
&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #FF9900"&gt;//else
&lt;br /&gt;//do&amp;nbsp;the&amp;nbsp;query
&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$result&lt;/span&gt;&lt;span style="color: #007700"&gt;=&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$db&lt;/span&gt;&lt;span style="color: #007700"&gt;-&amp;gt;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;query&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$query&lt;/span&gt;&lt;span style="color: #007700"&gt;);

&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #FF9900"&gt;//find&amp;nbsp;number&amp;nbsp;of&amp;nbsp;rows
&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$num_rows&lt;/span&gt;&lt;span style="color: #007700"&gt;=&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$result&lt;/span&gt;&lt;span style="color: #007700"&gt;-&amp;gt;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;num_rows&lt;/span&gt;&lt;span style="color: #007700"&gt;;
&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #FF9900"&gt;//if&amp;nbsp;no&amp;nbsp;rows&amp;nbsp;present&amp;nbsp;probably&amp;nbsp;when
&lt;br /&gt;//searching

&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #007700"&gt;if(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$num_rows&lt;/span&gt;&lt;span style="color: #007700"&gt;&amp;lt;=&lt;/span&gt;&lt;span style="color: #0000BB"&gt;0&lt;/span&gt;&lt;span style="color: #007700"&gt;)
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;echo&amp;nbsp;&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"&amp;lt;p&amp;gt;&amp;lt;i&amp;gt;No&amp;nbsp;Match&amp;nbsp;Found!&amp;lt;/i&amp;gt;&amp;lt;/p&amp;gt;"&lt;/span&gt;&lt;span style="color: #007700"&gt;;
&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #FF9900"&gt;//process&amp;nbsp;all&amp;nbsp;the&amp;nbsp;rows&amp;nbsp;one-by-one

&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #007700"&gt;for(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$i&lt;/span&gt;&lt;span style="color: #007700"&gt;=&lt;/span&gt;&lt;span style="color: #0000BB"&gt;0&lt;/span&gt;&lt;span style="color: #007700"&gt;;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$i&lt;/span&gt;&lt;span style="color: #007700"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$num_rows&lt;/span&gt;&lt;span style="color: #007700"&gt;;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$i&lt;/span&gt;&lt;span style="color: #007700"&gt;++)
&lt;br /&gt;{
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #FF9900"&gt;//fetch&amp;nbsp;one&amp;nbsp;row
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$row&lt;/span&gt;&lt;span style="color: #007700"&gt;=&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$result&lt;/span&gt;&lt;span style="color: #007700"&gt;-&amp;gt;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;fetch_row&lt;/span&gt;&lt;span style="color: #007700"&gt;();

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #FF9900"&gt;//print&amp;nbsp;the&amp;nbsp;values
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;echo&amp;nbsp;&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"&amp;lt;p&amp;gt;&amp;lt;span&amp;nbsp;style=\"font-size:&amp;nbsp;200%;\"&amp;gt;$row[1]:&amp;nbsp;&amp;lt;/span&amp;gt;&amp;nbsp;$row[2]&amp;lt;/p&amp;gt;"&lt;/span&gt;&lt;span style="color: #007700"&gt;;
&lt;br /&gt;}
&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #FF9900"&gt;//close&amp;nbsp;MySQL&amp;nbsp;connection

&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$db&lt;/span&gt;&lt;span style="color: #007700"&gt;-&amp;gt;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;close&lt;/span&gt;&lt;span style="color: #007700"&gt;();
&lt;br /&gt;
&lt;/span&gt;&lt;span style="color: #0000BB"&gt;?&amp;gt;&lt;/span&gt; &lt;/span&gt; &lt;/code&gt; 
&lt;p align="center"&gt;&lt;img src="http://one.arvind.googlepages.com/ph_book_w_search01.gif" alt="Performing Simple String Search Using PHP and MySQL" width="195" height="265" /&gt; 
&lt;/p&gt;
&lt;p&gt;It might now be obvious that we took this phonebook example due to the limitation 
  of &amp;#8220;like&amp;#8221; query to search for words within a string. That&amp;#8217;s 
  not to say it&amp;#8217;s not possible. In fact searching within string, even longer 
  ones is very easy and efficient using MySQL&amp;#8217;s built-in capability. But 
  we&amp;#8217;ll discuss that in some future posts.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Previous Posts:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/06/creating-simple-html-form-validation.html"&gt;Creating 
      a Simple Form Validation Script Using JavaScript&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/06/creating-simple-html-form-validation.html"&gt;Deigning 
      a Simple HTML Menu-Bar Using CSS &lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/06/blogger-method-to-add-link-to-this-post.html"&gt;Blogger: 
      Method to Add &amp;#8216;Link to This Post&amp;#8217; Widget on Your Posts &lt;/a&gt; 
    &lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/05/new-working-method-of-making-blogger.html"&gt;New 
      Working Method of Making Blogger Title Tags SEO Friendly&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/06/one-more-use-of-web-cookies.html"&gt;One 
      More Use of Web Cookies&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/33629562-2036353860421367180?l=learning-computer-programming.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TiGWE/~4/QQBNEHxUEvE" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://learning-computer-programming.blogspot.com/feeds/2036353860421367180/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://learning-computer-programming.blogspot.com/2008/07/performing-simple-string-search-using.html#comment-form" title="4 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/33629562/posts/default/2036353860421367180?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/33629562/posts/default/2036353860421367180?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/TiGWE/~3/QQBNEHxUEvE/performing-simple-string-search-using.html" title="Performing Simple String Search Using PHP and MySQL" /><author><name>Arvind Gupta</name><uri>http://www.blogger.com/profile/17199066124402939022</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="23" height="32" src="http://one.arvind.googlepages.com/arvind_gupta_photo.jpg" /></author><thr:total>4</thr:total><feedburner:origLink>http://learning-computer-programming.blogspot.com/2008/07/performing-simple-string-search-using.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEMDSXY5fyp7ImA9WxdVGEQ.&quot;"><id>tag:blogger.com,1999:blog-33629562.post-7690648188764061096</id><published>2008-07-24T14:51:00.001+05:30</published><updated>2008-07-24T15:11:18.827+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-07-24T15:11:18.827+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Web" /><category scheme="http://www.blogger.com/atom/ns#" term="Personal" /><title>RevResponse, Offer Freebies to Earn Money</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/ImsWUmFHK567xRH4PAgky22tt3U/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ImsWUmFHK567xRH4PAgky22tt3U/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/ImsWUmFHK567xRH4PAgky22tt3U/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ImsWUmFHK567xRH4PAgky22tt3U/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;img src="http://one.arvind.googlepages.com/revresponse.png" alt="RevResponse Affiliate Network" width="235" height="65" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;This is sort of a paid review. You don&amp;#8217;t normally find me doing this 
  but since I truly liked RevResponse at the first sight, I&amp;#8217;m writing this. 
  &lt;/em&gt; &lt;/p&gt;
&lt;p&gt;&lt;font size="4"&gt;Overview&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.revresponse.com/join.php/?refbrand=learning-computer-programming"&gt;RevResponse&lt;/a&gt; 
  (aff. link) is one-of-a-kind of affiliate network that pays you for promoting 
  Free Magazines, Technical Whitepapers, Software etc the topic of these materials 
  range from Agriculture to Software Development and from Bio-Technology to Transportaion 
  &amp;amp; Logistics. This means most content based website/blogs won&amp;#8217;t have 
  much problem finding relevant offers to promote. Since all magazines, whitepapers 
  etc. are free, it&amp;#8217;s kind of a Pay-Per-Lead affiliate network. The magazines, 
  that many presume to be SPAM, are not at all spammy rather are really useful 
  and informative. And as those are all free, it means great source of information 
  for your visitors and income for you!&lt;/p&gt;
&lt;p&gt;&lt;font size="4"&gt;Sign-Up&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;The &lt;a href="http://www.revresponse.com/join.php/?refbrand=learning-computer-programming"&gt;Sign-Up&lt;/a&gt; 
  (aff. link) process is pretty straightforward and doesn&amp;#8217;t require you 
  to fill any lengthy forms once you are done with that, they would contact you 
  within a few days (in my case less that 24-hours) to tell you whether your application 
  is accepted or not. If you have an informative blog/website, you won&amp;#8217;t 
  have any problems getting accepted even though your website/blog is on a free 
  host.&lt;/p&gt;
&lt;p&gt;&lt;font size="4"&gt;Promotional Materials&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Image Ads:&lt;/strong&gt; Basic ads in all standard sizes.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Text Ads:&lt;/strong&gt; Plain text ads. They also provide pre-written paragraphs. 
  It&amp;#8217;d be best if you personalize it.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Flash Widget:&lt;/strong&gt; Beside normal image based ads they also provide 
  interactive flash widgets. Catches eye and would prove to be useful for your 
  visitors.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Co-Branded Site:&lt;/strong&gt; Really great, like Amazon&amp;#8217;s astore, 
  RevResponse provides you with a customizable website with the same look as your 
  existing website. It is hosted on tradepub.com. It could be customized to create 
  your very own Magazine Catalog.&lt;/p&gt;
&lt;p&gt;&lt;font size="4"&gt;Earning Potential&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;If you choose the offers wisely and promote them using genuine reviews, in 
  other words to give genuine value to your visitors, there nothing stopping you 
  from earning, at least, more than traditional advertising (AdSense etc.) they 
  pay between $1.50 - $20 (as far as I&amp;#8217;ve heard), which is great. Another 
  great thing is unlike many other networks, RevResponse accepts leads (subscriptions, 
  downloads of the offers you promote) from international visitors too!&lt;/p&gt;
&lt;p&gt;&lt;font size="4"&gt;Conclusion&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Pros:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Company behind RevResponse is quite old (since 1996)&lt;/li&gt;
  &lt;li&gt;Great affiliate managers, support and &amp;#8220;personal&amp;#8221; feeling. They 
    have a blog and a forum to share and get ideas.&lt;/li&gt;
  &lt;li&gt;Payment via PayPal and Check.&lt;/li&gt;
  &lt;li&gt;Accepts international leads.&lt;/li&gt;
  &lt;li&gt;Offers that you can promote are FREE.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Cons:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Net-45 Payment scheme which means you&amp;#8217;re paid 45-days after the month 
    you earnings reach $50 (minimum payment threshold)&lt;/li&gt;
  &lt;li&gt;Web is so cluttered with spam that some people don&amp;#8217;t bother for &amp;#8220;freebies&amp;#8221; 
    anymore&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I&amp;#8217;d genuinely recommend &lt;a href="http://www.revresponse.com/join.php/?refbrand=learning-computer-programming"&gt;RevResponse&lt;/a&gt; 
  (aff. link) to anyone having a content blog/website. Do check it out!&lt;br /&gt;
&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/33629562-7690648188764061096?l=learning-computer-programming.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TiGWE/~4/0pGK44RlAFw" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://learning-computer-programming.blogspot.com/feeds/7690648188764061096/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://learning-computer-programming.blogspot.com/2008/07/revresponse-offer-freebies-to-earn.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/33629562/posts/default/7690648188764061096?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/33629562/posts/default/7690648188764061096?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/TiGWE/~3/0pGK44RlAFw/revresponse-offer-freebies-to-earn.html" title="RevResponse, Offer Freebies to Earn Money" /><author><name>Arvind Gupta</name><uri>http://www.blogger.com/profile/17199066124402939022</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="23" height="32" src="http://one.arvind.googlepages.com/arvind_gupta_photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://learning-computer-programming.blogspot.com/2008/07/revresponse-offer-freebies-to-earn.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkQMSH87eCp7ImA9WxdXE0w.&quot;"><id>tag:blogger.com,1999:blog-33629562.post-7019949817831490071</id><published>2008-06-24T17:30:00.001+05:30</published><updated>2008-06-24T17:56:29.100+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-06-24T17:56:29.100+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Personal" /><title>Reason For The Lack of Posts These Days...</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/S-olemYM_b6bHV3ElMPlvP8YDP4/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/S-olemYM_b6bHV3ElMPlvP8YDP4/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/S-olemYM_b6bHV3ElMPlvP8YDP4/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/S-olemYM_b6bHV3ElMPlvP8YDP4/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Today I&amp;#8217;ve got a bad news for you guys. It&amp;#8217;s that I won&amp;#8217;t 
  be able to blog for almost a month. Sorry guys, it&amp;#8217; I know it&amp;#8217;s 
  happened in the past but this time I&amp;#8217;ve got a pretty good excuse &amp;#8211; 
  EXAMS. That&amp;#8217;s right my exams starts 10th July and guess what, I haven&amp;#8217;t 
  studied much yet! It happens&amp;#8230;always happens&amp;#8230;&lt;/p&gt;
&lt;p&gt;Hope you&amp;#8217;d understand my problem, in the mean time you may want to read 
  some of my recent posts that got good readership:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/04/installing-apache-and-php-on-your-pc_20.html"&gt;Installing 
      Apache and PHP on your PC &lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/04/designing-simple-order-form-application.html"&gt;Designing 
      a Simple Order Form Application in PHP&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/04/designing-simple-quote-of-day-script-in.html"&gt;Designing 
      a Simple &amp;#8220;Quote of the Day&amp;#8221; Script in PHP&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/05/creating-contact-us-form-e-mail-version.html"&gt;Creating 
      a &amp;#8216;Contact Us&amp;#8217; Form (E-Mail Version) &lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/05/designing-simple-shout-box-script-in.html"&gt;Designing 
      a Simple &amp;#8216;Shout Box&amp;#8217; Script in PHP&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/05/complete-note-keeping-application.html"&gt;A 
      Complete Note Keeping Application in PHP&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/05/creating-simple-poll-script-in-php.html"&gt;Creating 
      a Simple Poll Script in PHP&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/05/new-working-method-of-making-blogger.html"&gt;New 
      Working Method of Making Blogger Title Tags SEO Friendly&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/06/basic-web-scraping-scraping-google.html"&gt;Basic 
      Web Scraping: Pulling Out Data From Google Search Results&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Enjoy!&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/33629562-7019949817831490071?l=learning-computer-programming.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TiGWE/~4/KTqTlQfqqNI" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://learning-computer-programming.blogspot.com/feeds/7019949817831490071/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://learning-computer-programming.blogspot.com/2008/06/reason-for-lack-of-posts-theses-days.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/33629562/posts/default/7019949817831490071?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/33629562/posts/default/7019949817831490071?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/TiGWE/~3/KTqTlQfqqNI/reason-for-lack-of-posts-theses-days.html" title="Reason For The Lack of Posts These Days..." /><author><name>Arvind Gupta</name><uri>http://www.blogger.com/profile/17199066124402939022</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="23" height="32" src="http://one.arvind.googlepages.com/arvind_gupta_photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://learning-computer-programming.blogspot.com/2008/06/reason-for-lack-of-posts-theses-days.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CUIAQX49fip7ImA9WxdQFUw.&quot;"><id>tag:blogger.com,1999:blog-33629562.post-9044670780703831045</id><published>2008-06-15T12:29:00.000+05:30</published><updated>2008-06-15T12:35:40.066+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-06-15T12:35:40.066+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Web" /><category scheme="http://www.blogger.com/atom/ns#" term="PHP" /><category scheme="http://www.blogger.com/atom/ns#" term="Useful Scripts" /><category scheme="http://www.blogger.com/atom/ns#" term="CSS" /><category scheme="http://www.blogger.com/atom/ns#" term="Complete Script" /><category scheme="http://www.blogger.com/atom/ns#" term="HTML" /><title>Creating Tool-Tip Text for WebPages Using CSS Only</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/UPJDXhZsWDHOc76K_5Av8MhfKl0/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/UPJDXhZsWDHOc76K_5Av8MhfKl0/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/UPJDXhZsWDHOc76K_5Av8MhfKl0/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/UPJDXhZsWDHOc76K_5Av8MhfKl0/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p align="center"&gt;&lt;img src="http://one.arvind.googlepages.com/tooltip01.JPG" alt="Creating Tool-Tip Text for WebPages Using CSS Only " width="212" height="256" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="4"&gt;&lt;em&gt;[&lt;/em&gt;&lt;/font&gt;&lt;em&gt;You might also be interseted in &lt;a href="http://learning-computer-programming.blogspot.com/2008/06/creating-simple-html-form-validation.html"&gt;Deigning 
  a Simple HTML Menu-Bar Using CSS&lt;/a&gt;&lt;font size="4"&gt;]&lt;/font&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;All right, so today we are going to use CSS along with some HTML to create 
  Tooltip text for WebPages without using JavaScript. Yeah, you heard it right 
  using only CSS and of course HTML. Do I need to explain what a Tooltip is, BTW? 
  Nah, you guys already know it. I do not think many sites use tooltips or anything 
  of that sort on their websites but in case you do or you just want to learn, 
  read on&amp;#8230;&lt;/p&gt;
&lt;p&gt;Well, the first thing that I want to tell is that the basic technique I&amp;#8217;ll 
  be using to create tooltips is not mine, I saw someone using it for a slightly 
  different purpose, I changes it to suite mine. As I said earlier we&amp;#8217;d 
  be using CSS and HTML only, I guess HTML is easier so here it is:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&lt;font color="#000000"&gt;&lt;font color="#800080"&gt;&amp;lt;a&lt;/font&gt; href=&lt;font color="#408080"&gt;&amp;quot;#&amp;quot;&lt;/font&gt; 
  class=&lt;font color="#408080"&gt;&amp;quot;tooltip&amp;quot;&lt;/font&gt;&amp;gt;Hover Here&lt;font color="#800080"&gt;&amp;lt;span&lt;/font&gt;&amp;gt;This 
  is the Tool-Tip Text&lt;font color="#800080"&gt;&amp;lt;/span&lt;/font&gt;&amp;gt;&lt;font color="#800080"&gt;&amp;lt;/a&lt;/font&gt;&amp;gt;&lt;/font&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;As you can see there is nothing special, a plain simple link but wait what 
  is that &lt;code&gt;&amp;lt;span&amp;gt;&lt;/code&gt; for? Good question! Well the text under the 
  &lt;code&gt;&amp;lt;span&amp;gt;&lt;/code&gt; tag wouldn&amp;#8217;t be visible unless you hover the 
  mouse over the link. When you do so that&amp;#8217;d become visible, neatly formatted 
  to look just like a real Tooltip text. But how? You might ask. It has been classified 
  (&lt;code&gt;class=&amp;quot;tooltip&amp;quot;&lt;/code&gt;) to do so.&lt;/p&gt;
&lt;p&gt;The heart of all this is the CSS:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&lt;font color="#000000"&gt;
  a.tooltip{
    /* for postioning the tool-tip box relative to the link */
    position:relative;

    /* no underline needed */
    text-decoration: none;
  }

  a.tooltip span{
    /* tool-tip text will not be visible initially */
    display: none;
  }

  a.tooltip:hover span{
    /* make tool-tip text visible */
    display:block;

    /* for postioning */
    position:absolute;
    top:&lt;font color="#ff0000"&gt;20px&lt;/font&gt;; left:&lt;font color="#ff0000"&gt;20px&lt;/font&gt;;
    padding: &lt;font color="#ff0000"&gt;5px&lt;/font&gt;;

    /* width of the tool-tip box
    if text is longer, it will be
    made into two lines */
    width:&lt;font color="#ff0000"&gt;150px&lt;/font&gt;;

    /* style the box to look like a tool-tip box */
    border:&lt;font color="#ff0000"&gt;1px&lt;/font&gt; solid #000;
    background-color:#FFFFAA;
    color:#000;
  }
&lt;/font&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now to make it more clear, I&amp;#8217;d break the whole code into smaller pieces 
  and discuss what that does:&lt;/p&gt;
&lt;p&gt;1.&lt;code&gt;&lt;font color="#000000"&gt;
  &lt;pre&gt;a.tooltip { position:relative; }&lt;/pre&gt;
  &lt;/font&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;This would make the tooltip (whenever) it appears to be positioned relatively 
  to where the link is.&lt;/p&gt;
&lt;p&gt;2. &lt;code&gt;&lt;font color="#000000"&gt;
  &lt;pre&gt;a.tooltip span { display: none; }&lt;/pre&gt;
  &lt;/font&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;It&amp;#8217;d (as you might have guessed) make the tooltip text (or the &lt;code&gt;&amp;lt;span&amp;gt;&lt;/code&gt; 
  tag) to be invisible.&lt;/p&gt;
&lt;p&gt;3. &lt;code&gt;&lt;font color="#000000"&gt;
  &lt;pre&gt;  a.tooltip:hover span {  
    display:block; 
    position:absolute; 
    top:&lt;font color="#ff0000"&gt;20px&lt;/font&gt;; 
    left:&lt;font color="#ff0000"&gt;20px&lt;/font&gt;; 
    padding: &lt;font color="#ff0000"&gt;5px&lt;/font&gt;; 
    width:&lt;font color="#ff0000"&gt;150px&lt;/font&gt;;
    border:&lt;font color="#ff0000"&gt;1px&lt;/font&gt; solid #000; 
    background-color:#FFFFAA; 
    color:#000; 
  }&lt;/pre&gt;
  &lt;/font&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;This defines what the &lt;code&gt;&amp;lt;span&amp;gt;&lt;/code&gt; tag would be when mouse is 
  hovered over the link.&lt;/p&gt;
&lt;p&gt;First it&amp;#8217;d make the &lt;code&gt;&amp;lt;span&amp;gt;&lt;/code&gt; visible (thus the tooltip 
  text) by using display: block;. Next it&amp;#8217;d position and style the &lt;code&gt;&amp;lt;span&amp;gt;&lt;/code&gt; 
  text to look like a &amp;#8220;Real&amp;#8221; tooltip. &lt;/p&gt;
&lt;p&gt;Easy! Now it is&amp;#8230;&lt;/p&gt;
&lt;p&gt;Here is the complete code:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&lt;font color="#000000"&gt;
  &lt;font color="#800080"&gt;&amp;lt;html&lt;/font&gt;&amp;gt;
  &lt;font color="#800080"&gt;&amp;lt;head&lt;/font&gt;&amp;gt;

  &lt;font color="#800080"&gt;&amp;lt;title&lt;/font&gt;&amp;gt;ToolTip Text Example&lt;font color="#800080"&gt;&amp;lt;/title&lt;/font&gt;&amp;gt;
  &lt;font color="#800080"&gt;&amp;lt;style&lt;/font&gt;&amp;gt;
  a.tooltip{
    /* for postioning the tool-tip box relative to the link */
    position:relative;

    /* no underline needed */
    text-decoration: none;
  }

  a.tooltip span{
    /* tool-tip text will not be visible initially */
    display: none;
  }

  a.tooltip:hover span{
    /* make tool-tip text visible */
    display:block;

    /* for postioning */
    position:absolute;
    top:&lt;font color="#ff0000"&gt;20px&lt;/font&gt;; left:&lt;font color="#ff0000"&gt;20px&lt;/font&gt;;
    padding: &lt;font color="#ff0000"&gt;5px&lt;/font&gt;;

    /* width of the tool-tip box
    if text is longer, it will be
    made into two lines */
    width:&lt;font color="#ff0000"&gt;150px&lt;/font&gt;;

    /* style the box to look like a tool-tip box */
    border:&lt;font color="#ff0000"&gt;1px&lt;/font&gt; solid #000;
    background-color:#FFFFAA;
    color:#000;
  }
    &lt;font color="#800080"&gt;&amp;lt;/style&lt;/font&gt;&amp;gt;

  &lt;font color="#800080"&gt;&amp;lt;/head&lt;/font&gt;&amp;gt;
  &lt;font color="#800080"&gt;&amp;lt;body&lt;/font&gt;&amp;gt;
  &lt;font color="#800080"&gt;&amp;lt;a&lt;/font&gt; href=&lt;font color="#408080"&gt;&amp;quot;#&amp;quot;&lt;/font&gt; class=&lt;font color="#408080"&gt;&amp;quot;tooltip&amp;quot;&lt;/font&gt;&amp;gt;Hover Here&lt;font color="#800080"&gt;&amp;lt;span&lt;/font&gt;&amp;gt;This is the Tool-Tip Text&lt;font color="#800080"&gt;&amp;lt;/span&lt;/font&gt;&amp;gt;&lt;font color="#800080"&gt;&amp;lt;/a&lt;/font&gt;&amp;gt;

  &lt;font color="#800080"&gt;&amp;lt;/body&lt;/font&gt;&amp;gt;
  &lt;font color="#800080"&gt;&amp;lt;/html&lt;/font&gt;&amp;gt;
&lt;/font&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Previous Posts:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/06/basic-web-scraping-scraping-google.html"&gt;Basic 
      Web Scraping: Pulling Out Data From Google Results&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/06/creating-simple-html-form-validation.html"&gt;Creating 
      a Simple Form Validation Script Using JavaScript&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/06/creating-simple-html-form-validation.html"&gt;Deigning 
      a Simple HTML Menu-Bar Using CSS &lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/06/blogger-method-to-add-link-to-this-post.html"&gt;Blogger: 
      Method to Add &amp;#8216;Link to This Post&amp;#8217; Widget on Your Posts &lt;/a&gt; 
    &lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/05/new-working-method-of-making-blogger.html"&gt;New 
      Working Method of Making Blogger Title Tags SEO Friendly&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/33629562-9044670780703831045?l=learning-computer-programming.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TiGWE/~4/HKdEAhf_17A" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://learning-computer-programming.blogspot.com/feeds/9044670780703831045/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://learning-computer-programming.blogspot.com/2008/06/creating-tool-tip-text-for-webpages.html#comment-form" title="12 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/33629562/posts/default/9044670780703831045?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/33629562/posts/default/9044670780703831045?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/TiGWE/~3/HKdEAhf_17A/creating-tool-tip-text-for-webpages.html" title="Creating Tool-Tip Text for WebPages Using CSS Only" /><author><name>Arvind Gupta</name><uri>http://www.blogger.com/profile/17199066124402939022</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="23" height="32" src="http://one.arvind.googlepages.com/arvind_gupta_photo.jpg" /></author><thr:total>12</thr:total><feedburner:origLink>http://learning-computer-programming.blogspot.com/2008/06/creating-tool-tip-text-for-webpages.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEYESX05fSp7ImA9WxNTGUw.&quot;"><id>tag:blogger.com,1999:blog-33629562.post-43173794931329519</id><published>2008-06-11T12:56:00.003+05:30</published><updated>2009-08-22T10:11:48.325+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-08-22T10:11:48.325+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Web" /><category scheme="http://www.blogger.com/atom/ns#" term="PHP" /><category scheme="http://www.blogger.com/atom/ns#" term="Useful Scripts" /><category scheme="http://www.blogger.com/atom/ns#" term="HTML" /><category scheme="http://www.blogger.com/atom/ns#" term="Web Scraping" /><title>Basic Web Scraping: Pulling Out Data From Google Search Results</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/74cqCy1IqnqJg8zIeJc3S6YoqMc/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/74cqCy1IqnqJg8zIeJc3S6YoqMc/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/74cqCy1IqnqJg8zIeJc3S6YoqMc/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/74cqCy1IqnqJg8zIeJc3S6YoqMc/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;style type="text/css"&gt;
&lt;!--
--&gt;
&lt;/style&gt;&lt;p align="center"&gt;&lt;img src="http://one.arvind.googlepages.com/google_scarper_02.JPG" alt="Basic Web Scraping: Scraping Google Search Results" width="255" height="307" /&gt;&lt;/p&gt;
&lt;p&gt;[&lt;b&gt;UPDATE (22-AUG-2009): &lt;/b&gt;THIS IS THE NEW WORKING VERSION.]&lt;/p&gt;
&lt;p&gt;Today we are going to discuss a bit advanced topic, not in the sense that it&amp;#8217;d 
  be difficult to understand (I always try to make things easier anyway) but that 
  you won&amp;#8217;t find an apparent use of it. What we are going to do today is 
  what is called Web Scraping. By the way web scraping means retrieving data from 
  web and pulling out useful information out of it for our use. Of course this 
  wouldn&amp;#8217;t be the next best web scraper rather it would la a basic foundation 
  on how simple a web scraper can be. &lt;/p&gt;
&lt;p&gt;OK let&amp;#8217;s kick off guys!&lt;/p&gt;
&lt;p&gt;As is obvious we are going to scrape Google&amp;#8217;s Web Search Results to retrieve 
  the number of pages indexed for a search term.&lt;/p&gt;
&lt;p align="center"&gt;&lt;img src="http://one.arvind.googlepages.com/google_scraper_01.JPG" alt="Scarping Google Results for Number of Pages Indexed" width="409" height="272" /&gt;&lt;/p&gt;
&lt;p&gt;To retrieve results for a search term we need the URL, for this fire up your 
  favorite Browser and browse to the Search Engine&amp;#8217;s (Google, or whatever) 
  homepage, type in any search query and hit enter.&lt;/p&gt;
&lt;p&gt;OK now look at the address bar, in my case I looked like below, your&amp;#8217; 
  should be similar or whatever:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;http://www.google.com/search?hl=en&amp;amp;q=learning+c&amp;amp;btnG=Google+Search&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;
  On inspection you can see pour search term in the URL which is &amp;#8216;URL Encoded&amp;#8217; 
  (changes some character such as spaces to codes). There we have it, you can 
  place any search keyword (urlencoded, very simple with PHP&amp;#8217;s in-built 
  function) and fetch that page. But how in a script, you might ask. Because that 
  is what we need.&lt;/p&gt;
&lt;p&gt;Well using the following function:&lt;/p&gt;
&lt;p&gt;&lt;strikeout&gt;&lt;code&gt;&lt;span style="color: #000000"&gt;&lt;span style="color: #0000BB"&gt;file_get_contents&lt;/span&gt;&lt;span style="color: #007700"&gt;();&lt;/span&gt;&lt;span style="color: #DD0000"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/strikeout&gt;&lt;/p&gt;
&lt;p&gt;[&lt;b&gt;UPDATE:&lt;/b&gt; WE'LL BE USING THE FOLLOWING USER-DEFINED FUNCTION INSTEAD. READ COMMENTS FOR MORE INFORMATION:&lt;/p&gt;
&lt;code&gt;&lt;span style="color: #000000"&gt;
&lt;span style="color: #0000BB"&gt;&lt;/span&gt;&lt;span style="color: #007700"&gt;function&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;my_fetch&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$url&lt;/span&gt;&lt;span style="color: #007700"&gt;,&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$user_agent&lt;/span&gt;&lt;span style="color: #007700"&gt;=&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'Mozilla/4.0&amp;nbsp;(compatible;&amp;nbsp;MSIE&amp;nbsp;5.01;&amp;nbsp;Windows&amp;nbsp;NT&amp;nbsp;5.0)'&lt;/span&gt;&lt;span style="color: #007700"&gt;)

&lt;br /&gt;{
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$ch&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;=&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;curl_init&lt;/span&gt;&lt;span style="color: #007700"&gt;();
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;curl_setopt&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$ch&lt;/span&gt;&lt;span style="color: #007700"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;CURLOPT_URL&lt;/span&gt;&lt;span style="color: #007700"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$url&lt;/span&gt;&lt;span style="color: #007700"&gt;);
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;curl_setopt&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$ch&lt;/span&gt;&lt;span style="color: #007700"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;CURLOPT_USERAGENT&lt;/span&gt;&lt;span style="color: #007700"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$user_agent&lt;/span&gt;&lt;span style="color: #007700"&gt;);

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;curl_setopt&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$ch&lt;/span&gt;&lt;span style="color: #007700"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;CURLOPT_HEADER&lt;/span&gt;&lt;span style="color: #007700"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;0&lt;/span&gt;&lt;span style="color: #007700"&gt;);
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;curl_setopt&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$ch&lt;/span&gt;&lt;span style="color: #007700"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;CURLOPT_RETURNTRANSFER&lt;/span&gt;&lt;span style="color: #007700"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;1&lt;/span&gt;&lt;span style="color: #007700"&gt;);
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;curl_setopt&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$ch&lt;/span&gt;&lt;span style="color: #007700"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;CURLOPT_REFERER&lt;/span&gt;&lt;span style="color: #007700"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'http://www.google.com/'&lt;/span&gt;&lt;span style="color: #007700"&gt;);

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$result&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;=&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;curl_exec&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$ch&lt;/span&gt;&lt;span style="color: #007700"&gt;);
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;curl_close&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$ch&lt;/span&gt;&lt;span style="color: #007700"&gt;);
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$result&lt;/span&gt;&lt;span style="color: #007700"&gt;;
&lt;br /&gt;}
&lt;/span&gt;&lt;/span&gt;

&lt;/code&gt;
&lt;p&gt;]&lt;/p&gt;
&lt;p&gt;If you have been following this blog for sometime, you might remember we once 
  used it in my &lt;em&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/05/designing-simple-shout-box-script-in.html"&gt;Creating 
  a Simple Shout Box in PHP&lt;/a&gt;&lt;/em&gt; post to fetch contents from a local file. 
  Yeah its beauty is that it can fetch remote (HTTP) files too.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&lt;span style="color: #000000"&gt;&lt;span style="color: #0000BB"&gt;$data &lt;/span&gt;&lt;span style="color: #007700"&gt;=&lt;/span&gt;&lt;span style="color: #0000BB"&gt; file_get_contents&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"http://www.google.com/search?hl=en&amp;amp;q=learning+c&lt;/span&gt;&lt;span style="color: #DD0000"&gt;&amp;amp;btnG=Google+Search"&lt;/span&gt;&lt;span style="color: #007700"&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;[&lt;b&gt;UPDATE:&lt;/b&gt; NOW USING:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&lt;span style="color: #000000"&gt;&lt;span style="color: #0000BB"&gt;$data &lt;/span&gt;&lt;span style="color: #007700"&gt;=&lt;/span&gt;&lt;span style="color: #0000BB"&gt; my_fetch&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"http://www.google.com/search?hl=en&amp;amp;q=learning+c&amp;amp;btnG=Google+Search"&lt;/span&gt;&lt;span style="color: #007700"&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;]&lt;/p&gt;
&lt;p&gt;Above code will fetch the Google Search Results for the keyword we searched 
  for in the browser, $data will contain the HTML source.&lt;/p&gt;
&lt;p&gt;Since we have to scrape the total number of pages indexed for a particular 
  search term (displayed as &amp;#8220;Results 1 - 10 of about XXXX &amp;#8230;&amp;#8221;) 
  we would find some text near that number(XXXX in this case). In this case that 
  text is simply &amp;#8220;Results 1 - 10 of about&amp;#8221;, its also unique throughout 
  the page hence if we could find it in the code returned we can easily find the 
  needed data. One more thing we can ease off searching by first stripping off 
  HTML from the code returned so that only text remains. This part can be implemented 
  as below:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&lt;span style="color: #000000"&gt;&lt;span style="color: #0000BB"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$data&lt;/span&gt;&lt;span style="color: #007700"&gt;=&lt;/span&gt;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;my_fetch&lt;/span&gt;&lt;span style="color: #000000"&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"http://www.google.com/search?hl=en&amp;amp;q="&lt;/span&gt;&lt;span style="color: #007700"&gt;.&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$s&lt;/span&gt;&lt;span style="color: #007700"&gt;.&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"&amp;amp;btnG=Google+Search"&lt;/span&gt;&lt;span style="color: #007700"&gt;); 
  &lt;br /&gt;
  &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
  &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #FF9900"&gt;//strip&amp;nbsp;off&amp;nbsp;HTML 
  &lt;br /&gt;
  &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$data&lt;/span&gt;&lt;span style="color: #007700"&gt;=&lt;/span&gt;&lt;span style="color: #0000BB"&gt;strip_tags&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$data&lt;/span&gt;&lt;span style="color: #007700"&gt;); 
  &lt;/span&gt;&lt;span style="color: #FF9900"&gt;&lt;br /&gt;
  &lt;br /&gt;
  &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$find&lt;/span&gt;&lt;span style="color: #007700"&gt;=&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'Results&amp;nbsp;1&amp;nbsp;-&amp;nbsp;10&amp;nbsp;of&amp;nbsp;about&amp;nbsp;'&lt;/span&gt;&lt;span style="color: #007700"&gt;; 
  &lt;br /&gt;
  &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$find2&lt;/span&gt;&lt;span style="color: #007700"&gt;=&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'&amp;nbsp;for'&lt;/span&gt;&lt;span style="color: #007700"&gt;; 
  &lt;br /&gt;
  &lt;br /&gt;
  &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #FF9900"&gt;//have&amp;nbsp;text&amp;nbsp;beginning&amp;nbsp;from&amp;nbsp;$find 
  &lt;br /&gt;
  &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$data&lt;/span&gt;&lt;span style="color: #007700"&gt;=&lt;/span&gt;&lt;span style="color: #0000BB"&gt;strstr&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$data&lt;/span&gt;&lt;span style="color: #007700"&gt;,&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$find&lt;/span&gt;&lt;span style="color: #007700"&gt;); 
  &lt;br /&gt;
  &lt;br /&gt;
  &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #FF9900"&gt;//find&amp;nbsp;position&amp;nbsp;of&amp;nbsp;$find2 
  &lt;br /&gt;
  &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$pos&lt;/span&gt;&lt;span style="color: #007700"&gt;=&lt;/span&gt;&lt;span style="color: #0000BB"&gt;strpos&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$data&lt;/span&gt;&lt;span style="color: #007700"&gt;,&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$find2&lt;/span&gt;&lt;span style="color: #007700"&gt;); 
  &lt;br /&gt;
  &lt;br /&gt;
  &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #FF9900"&gt;//take&amp;nbsp;substring&amp;nbsp;out,&amp;nbsp;which'd&amp;nbsp;be&amp;nbsp;the&amp;nbsp;number&amp;nbsp;we&amp;nbsp;want 
  &lt;br /&gt;
  &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$search_number&lt;/span&gt;&lt;span style="color: #007700"&gt;=&lt;/span&gt;&lt;span style="color: #0000BB"&gt;substr&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$data&lt;/span&gt;&lt;span style="color: #007700"&gt;,&lt;/span&gt;&lt;span style="color: #0000BB"&gt;strlen&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$find&lt;/span&gt;&lt;span style="color: #007700"&gt;),&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$pos&lt;/span&gt;&lt;span style="color: #007700"&gt;-&lt;/span&gt;&lt;span style="color: #0000BB"&gt;strlen&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$find&lt;/span&gt;&lt;span style="color: #007700"&gt;)); 
  &lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Here is the complete code:&lt;/p&gt;
&lt;code&gt;&lt;span style="color: #000000"&gt;
&amp;lt;html&amp;gt;
&lt;br /&gt;&amp;lt;head&amp;gt;
&lt;br /&gt;&amp;lt;title&amp;gt;Google&amp;nbsp;Result&amp;nbsp;Scraper&amp;lt;/title&amp;gt;
&lt;br /&gt;&amp;lt;/head&amp;gt;
&lt;br /&gt;
&lt;br /&gt;&amp;lt;body&amp;gt;
&lt;br /&gt;&amp;lt;p&amp;nbsp;align="center"&amp;nbsp;style="font-size:&amp;nbsp;500%"&amp;gt;&amp;lt;font&amp;nbsp;color="#0000FF"&amp;gt;G&amp;lt;/font&amp;gt;&amp;lt;font

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;color="#FF0000"&amp;gt;o&amp;lt;/font&amp;gt;&amp;lt;font&amp;nbsp;color="#FFFF00"&amp;gt;o&amp;lt;/font&amp;gt;&amp;lt;font
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;color="#0000FF"&amp;gt;g&amp;lt;/font&amp;gt;&amp;lt;font&amp;nbsp;color="#00FF00"&amp;gt;l&amp;lt;/font&amp;gt;&amp;lt;font
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;color="#FF0000"&amp;gt;e&amp;lt;/font&amp;gt;&amp;lt;font&amp;nbsp;size="2"&amp;gt;&amp;lt;br&amp;nbsp;/&amp;gt;

&lt;br /&gt;Result&amp;nbsp;Scraper&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;
&lt;br /&gt;
&lt;br /&gt;&lt;span style="color: #0000BB"&gt;&amp;lt;?php
&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #007700"&gt;function&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;my_fetch&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$url&lt;/span&gt;&lt;span style="color: #007700"&gt;,&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$user_agent&lt;/span&gt;&lt;span style="color: #007700"&gt;=&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'Mozilla/4.0&amp;nbsp;(compatible;&amp;nbsp;MSIE&amp;nbsp;5.01;&amp;nbsp;Windows&amp;nbsp;NT&amp;nbsp;5.0)'&lt;/span&gt;&lt;span style="color: #007700"&gt;)

&lt;br /&gt;{
&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$ch&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;=&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;curl_init&lt;/span&gt;&lt;span style="color: #007700"&gt;();
&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;curl_setopt&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$ch&lt;/span&gt;&lt;span style="color: #007700"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;CURLOPT_URL&lt;/span&gt;&lt;span style="color: #007700"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$url&lt;/span&gt;&lt;span style="color: #007700"&gt;);
&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;curl_setopt&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$ch&lt;/span&gt;&lt;span style="color: #007700"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;CURLOPT_USERAGENT&lt;/span&gt;&lt;span style="color: #007700"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$user_agent&lt;/span&gt;&lt;span style="color: #007700"&gt;);

&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;curl_setopt&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$ch&lt;/span&gt;&lt;span style="color: #007700"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;CURLOPT_HEADER&lt;/span&gt;&lt;span style="color: #007700"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;0&lt;/span&gt;&lt;span style="color: #007700"&gt;);
&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;curl_setopt&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$ch&lt;/span&gt;&lt;span style="color: #007700"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;CURLOPT_RETURNTRANSFER&lt;/span&gt;&lt;span style="color: #007700"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;1&lt;/span&gt;&lt;span style="color: #007700"&gt;);
&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;curl_setopt&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$ch&lt;/span&gt;&lt;span style="color: #007700"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;CURLOPT_REFERER&lt;/span&gt;&lt;span style="color: #007700"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'http://www.google.com/'&lt;/span&gt;&lt;span style="color: #007700"&gt;);

&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$result&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;=&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;curl_exec&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$ch&lt;/span&gt;&lt;span style="color: #007700"&gt;);
&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;curl_close&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$ch&lt;/span&gt;&lt;span style="color: #007700"&gt;);
&lt;br /&gt;return&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$result&lt;/span&gt;&lt;span style="color: #007700"&gt;;
&lt;br /&gt;}
&lt;br /&gt;
&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$s&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;=&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$_GET&lt;/span&gt;&lt;span style="color: #007700"&gt;[&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'s'&lt;/span&gt;&lt;span style="color: #007700"&gt;];

&lt;br /&gt;if&amp;nbsp;(isset(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$s&lt;/span&gt;&lt;span style="color: #007700"&gt;))
&lt;br /&gt;{
&lt;br /&gt;echo&amp;nbsp;&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"&amp;lt;p&amp;gt;&amp;lt;i&amp;gt;Search&amp;nbsp;for&amp;nbsp;$s&amp;lt;/i&amp;gt;&amp;lt;/p&amp;gt;"&lt;/span&gt;&lt;span style="color: #007700"&gt;;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$s&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;=&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;urlencode&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$s&lt;/span&gt;&lt;span style="color: #007700"&gt;);

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$data&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;=&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;my_fetch&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"http://www.google.com/search?hl=en&amp;amp;q="&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;.&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$s&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;.&amp;nbsp;&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"&amp;amp;btnG=Google+Search"&lt;/span&gt;&lt;span style="color: #007700"&gt;);
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #FF8000"&gt;//strip&amp;nbsp;off&amp;nbsp;HTML
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$data&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;=&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;strip_tags&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$data&lt;/span&gt;&lt;span style="color: #007700"&gt;);

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #FF8000"&gt;//now&amp;nbsp;$data&amp;nbsp;only&amp;nbsp;has&amp;nbsp;text&amp;nbsp;NO&amp;nbsp;HTML
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//these&amp;nbsp;have&amp;nbsp;to&amp;nbsp;found&amp;nbsp;out&amp;nbsp;in&amp;nbsp;the&amp;nbsp;fetched&amp;nbsp;data
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$find&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;=&amp;nbsp;&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'Results&amp;nbsp;1&amp;nbsp;-&amp;nbsp;10&amp;nbsp;of&amp;nbsp;about&amp;nbsp;'&lt;/span&gt;&lt;span style="color: #007700"&gt;;

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$find2&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;=&amp;nbsp;&lt;/span&gt;&lt;span style="color: #DD0000"&gt;'&amp;nbsp;for'&lt;/span&gt;&lt;span style="color: #007700"&gt;;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #FF8000"&gt;//have&amp;nbsp;text&amp;nbsp;beginning&amp;nbsp;from&amp;nbsp;$find
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$data&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;=&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;strstr&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$data&lt;/span&gt;&lt;span style="color: #007700"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$find&lt;/span&gt;&lt;span style="color: #007700"&gt;);

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #FF8000"&gt;//find&amp;nbsp;position&amp;nbsp;of&amp;nbsp;$find2
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//there&amp;nbsp;might&amp;nbsp;be&amp;nbsp;many&amp;nbsp;occurence
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//but&amp;nbsp;it'd&amp;nbsp;give&amp;nbsp;position&amp;nbsp;of&amp;nbsp;the&amp;nbsp;first&amp;nbsp;one,

&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//which&amp;nbsp;is&amp;nbsp;what&amp;nbsp;we&amp;nbsp;want,&amp;nbsp;anyway
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$pos&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;=&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;strpos&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$data&lt;/span&gt;&lt;span style="color: #007700"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$find2&lt;/span&gt;&lt;span style="color: #007700"&gt;);
&lt;br /&gt;
&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #FF8000"&gt;//take&amp;nbsp;substring&amp;nbsp;out,&amp;nbsp;which'd&amp;nbsp;be&amp;nbsp;the&amp;nbsp;number&amp;nbsp;we&amp;nbsp;want

&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$search_number&lt;/span&gt;&lt;span style="color: #007700"&gt;=&lt;/span&gt;&lt;span style="color: #0000BB"&gt;substr&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$data&lt;/span&gt;&lt;span style="color: #007700"&gt;,&lt;/span&gt;&lt;span style="color: #0000BB"&gt;strlen&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$find&lt;/span&gt;&lt;span style="color: #007700"&gt;),&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$pos&lt;/span&gt;&lt;span style="color: #007700"&gt;-&lt;/span&gt;&lt;span style="color: #0000BB"&gt;strlen&lt;/span&gt;&lt;span style="color: #007700"&gt;(&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$find&lt;/span&gt;&lt;span style="color: #007700"&gt;));
&lt;br /&gt;

&lt;br /&gt;echo&amp;nbsp;&lt;/span&gt;&lt;span style="color: #DD0000"&gt;"Pages&amp;nbsp;Indexed:&amp;nbsp;$search_number"&lt;/span&gt;&lt;span style="color: #007700"&gt;;
&lt;br /&gt;}
&lt;br /&gt;else
&lt;br /&gt;{
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;?&amp;gt;
&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;&amp;lt;form&amp;nbsp;name="form1"&amp;nbsp;id="form1"&amp;nbsp;method="get"&amp;nbsp;action=""&amp;gt;

&lt;br /&gt;&amp;lt;div&amp;nbsp;align="center"&amp;gt;
&lt;br /&gt;&amp;lt;p&amp;gt;&amp;nbsp;&amp;nbsp;&amp;lt;input&amp;nbsp;name="s"&amp;nbsp;type="text"&amp;nbsp;id="s"&amp;nbsp;size="50"&amp;nbsp;/&amp;gt;
&lt;br /&gt;&amp;lt;input&amp;nbsp;type="submit"&amp;nbsp;name="Submit"&amp;nbsp;value="Count"&amp;nbsp;/&amp;gt;&amp;lt;/p&amp;gt;

&lt;br /&gt;&amp;lt;/div&amp;gt;
&lt;br /&gt;&amp;lt;/form&amp;gt;
&lt;br /&gt;&amp;lt;p&amp;gt;&amp;amp;nbsp;&amp;lt;/p&amp;gt;
&lt;br /&gt;&amp;lt;p&amp;gt;&amp;amp;nbsp;&amp;lt;/p&amp;gt;
&lt;br /&gt;&amp;lt;p&amp;gt;&amp;amp;nbsp;&amp;lt;/p&amp;gt;
&lt;br /&gt;&amp;lt;p&amp;gt;&amp;amp;nbsp;&amp;lt;/p&amp;gt;

&lt;br /&gt;&amp;lt;p&amp;gt;
&lt;br /&gt;&lt;span style="color: #0000BB"&gt;&amp;lt;?php
&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #007700"&gt;}
&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;?&amp;gt;
&lt;br /&gt;&lt;/span&gt;&amp;lt;/p&amp;gt;
&lt;br /&gt;&amp;lt;p&amp;nbsp;align="right"&amp;gt;&amp;lt;font&amp;nbsp;size="2"&amp;gt;by&amp;nbsp;&amp;lt;a
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;href="http://learning-computer-programming.blogspot.com/"&amp;gt;Learning
&lt;br /&gt;Computer&amp;nbsp;Programming&amp;lt;/a&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;

&lt;br /&gt;&amp;lt;/body&amp;gt;
&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;
&lt;p&gt;Wow, our first scarper is completed. It has a nice interface, you type in search 
  phrase click &amp;#8216;Count&amp;#8217; and there you are. It displays the number of 
  pages that contains that term same as on Google.&lt;/p&gt;
&lt;p&gt;Have fun guys and do comment!&lt;/p&gt;
&lt;p&gt;P.S.: You might want to read &lt;em&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/04/string-manipulation-functions-in-php.html"&gt;String 
  Manipulation Function in PHP I&lt;/a&gt;&lt;/em&gt; and &lt;em&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/05/string-manipulation-functions-in-php-ii.html"&gt;String 
  Manipulation Function in PHP II &lt;/a&gt;&lt;/em&gt;if you are not much familiar with the 
  string manipulation functions we are using in the code above.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Previous Posts:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/06/creating-simple-html-form-validation.html"&gt;Creating 
      a Simple Form Validation Script Using JavaScript&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/06/creating-simple-html-form-validation.html"&gt;Deigning 
      a Simple HTML Menu-Bar Using CSS &lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/06/blogger-method-to-add-link-to-this-post.html"&gt;Blogger: 
      Method to Add &amp;#8216;Link to This Post&amp;#8217; Widget on Your Posts &lt;/a&gt; 
    &lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/05/new-working-method-of-making-blogger.html"&gt;New 
      Working Method of Making Blogger Title Tags SEO Friendly&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt; 
    &lt;p&gt;&lt;a href="http://learning-computer-programming.blogspot.com/2008/06/one-more-use-of-web-cookies.html"&gt;One 
      More Use of Web Cookies&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/33629562-43173794931329519?l=learning-computer-programming.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TiGWE/~4/4tEVrmIbUN0" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://learning-computer-programming.blogspot.com/feeds/43173794931329519/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://learning-computer-programming.blogspot.com/2008/06/basic-web-scraping-scraping-google.html#comment-form" title="33 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/33629562/posts/default/43173794931329519?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/33629562/posts/default/43173794931329519?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/TiGWE/~3/4tEVrmIbUN0/basic-web-scraping-scraping-google.html" title="Basic Web Scraping: Pulling Out Data From Google Search Results" /><author><name>Arvind Gupta</name><uri>http://www.blogger.com/profile/17199066124402939022</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="23" height="32" src="http://one.arvind.googlepages.com/arvind_gupta_photo.jpg" /></author><thr:total>33</thr:total><feedburner:origLink>http://learning-computer-programming.blogspot.com/2008/06/basic-web-scraping-scraping-google.html</feedburner:origLink></entry></feed>

