iNET Interactive - Online Advertising Agency
          
   Home    Authors    About    Login    Contact Us
   Search:   
Advanced Search     
  Articles

  ASP (26)
  ASP.NET (19)
  C and C++ (4)
  CFML (2)
  CGI and Perl (16)
  Flash (2)
  Java (7)
  JavaScript (28)
  PHP (92)
  MySQL (13)
  MSSQL (3)
  HTML (34)
  SEO (9)
  Visual Basic (12)
  CSS (13)
  SSI (5)
  XML (12)
  C# (14)

  Developer News

May 12, 2008
Film Makers, Bands and Comedians Welcome on MySpace
About
 
May 12, 2008
Software Engineering for Ajax
WebReference.com
 
May 12, 2008
What is the Head Tag For?
About
 
May 11, 2008
Improving accessibility for motor impaired users
WebDevTips UK
 
May 11, 2008
10 ways to orientate users on your site
WebDevTips UK
 
May 11, 2008
Web Design Clinic - Rros restoration camp 2006
About
 
Courtesy of moreover.com
 
Want to receive new articles via e-mail? Click here!
/Home /PHP /Introduction to PHP

PHP Lesson One - Entry Point 

  Views:    29807
  Votes:    5
by James N Hitz 1/23/04 Rating: 

Synopsis:

Lesson 1: introduces the PHP basics outlining PHP strengths, weaknesses and also where to get PHP.
Pages: firstback1 2 3 4 5 6 8 9 forwardlast
The Article

Ambitious Alternative

You must be feeling ambitious by now. I know I am. So let's make our program do a little more than just "Hello World"-ing the PHP world. Let's say "Hello PHP World", output a "<HR>" and a line saying "PHP seems like fun" in red and a size of 4. In "plain HTML" this would be printed thus:

<h2>Hello PHP World
<hr>
<p><font size="4" color="red">PHP seems like fun</font>

In PHP there is a right solution and a wrong solution. Here is the wrong solution:

<html><head><title>Hello PHP World</title></head>
<body>
<?php
     print("<h2>Hello PHP World");
     echo("<hr>");
     print("<p><font size="3" color="red">PHP seems like fun</font></p>");
?>
</body></html>

What! This is wrong!? Perl and Java(Script) programmers must be smiling by now. The other like you (oops! Sorry) are just buffled. Let's take a refresher.

In point number e) of the points (observations) made earlier we said the text being output should be put WITHIN double quotes. Look at line 6 in our code. How many double quotes do you see? Well. The PHP preprocessor would be as confused as you if you gave it the above code to munch :-O.

How about that echo thingie on line 5. Well. That's fine. There are more than one ways of killing a rat: dip it in hot water, chock it with a blanket, smash it with a slipper, shoot with a canon...

In the same way, there are several ways of outputing text, print() just happens to be one of them and echo() is one of the other sisters.

All right. So the echo() is not a blunder but the quotes in line 6 are. Now What!?

Pages: firstback1 2 3 4 5 6 8 9 forwardlast

Similar/related articles:


 
  Sponsors