PHP102

From mi-linux
Revision as of 11:42, 19 January 2007 by In6480 (talk | contribs)
Jump to navigationJump to search

I've got my first file working, what's next?

As you know from CP1082 (HTML), writing valid HTML is critical to the success of a website - this is no different when writing PHP.

  • PHP can output HTML

For the vast majority of what you want to accomplish with PHP, you will likely what to output some information in the form of a webpage. Webpages need to consist of valid HTML, so PHP needs to output VALID HTML. We'll continue to use Transitional HTML 4.01 unless you feel confident enough to attempt the Strict version - either will be valid for assessments on CP1079.

First VALID PHP/HTML page (EXERCISE 2)

1. Open your preferred editor

2. Code the following exactly - DO NOT CUT AND PASTE - you will not learn by just pasting this.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">

 <HTML lang="en">
   <HEAD>
     <META http-equiv="Content-Type" content="text/html;charset=UTF-8">
     <TITLE>My First Valid HTML/PHP page</TITLE>
   </HEAD>
   <BODY>
 <?
   $name="MyName";
   echo "Hello - I am ".$name;
 ?>
   </BODY>
 </HTML>

3. Save this in your public_html folder as "test2.php"

4. Open your preferred browser and point it to http://mi-linux.wlv.ac.uk/~YOURSTUDENTNUMBER/test2.php

5. The result should look like the following screenshot - if it does not, scroll down to Troubleshooting Exercise 2 for common problems:

Second.png

Troubleshooting Exercise 2

Common problems

1.

2.

3.