We have seen that XHTML does that create static pages. PHP can get in XHTML code to make it dynamic! See the code of a basic XHTML page that displays "Hello" and the same page in PHP (PHP page must carry the extension. Php for the server to know that this page will be parsed by PHP before to be sent, otherwise you will have the PHP source code that is displayed to visitors, which could be unfortunate, especially if you set passwords!
Here are the basics of our code XHTML page:
Code:
<html xmlns= "http://www.w3.org/1999/xhtml" xml:lang= "eng" lang= "eng" >
<head >
<title> Here the title of your page </title>
<meta http-equiv= "Content-Type" content= "text/html; charset=iso-8859-1" />
<link rel= "stylesheet" href= "style.css" media= "screen" type= "text/css" />
</head>
<body>
Hello!
</body>
</html>
We will now turn this page in PHP, we will use to display text function (which is not really one, but I will not complicate the task) echo (). This feature allows you to display text, we will see how to use it in detail later in the PHP.
Code:
<html xmlns= "http://www.w3.org/1999/xhtml" xml:lang= "fr" lang= "fr" >
<head >
<title>Here the title of your page </title>
<meta http-equiv= "Content-Type" content= "text/html; charset=iso-8859-1" />
<link rel= "stylesheet" href= "style.css" media= "screen" type= "text/css" />
</head>
<body>
<?php echo ' Hello! ' ; ?>
</body>
</html>
It notes that the PHP code in HTML (remember to give your page an extension. Php). At first glance, it does not have many differences, and one may wonder about the usefulness of such a code. For now, the usefulness of such a code is zero. Why? because use PHP to generate static content (here, your page will display all the time Hello!) is unnecessary because it creates a loss of performance (the server needs to process the PHP page before sending it, unlike a page (X) HTML). But patience! PHP is not limited to displaying text (and fortunately), first begin with the basics and deepen then
We have just seen an example of PHP code embedded in XHTML code, but PHP may well be part of a file without XHTML around. Never forget that PHP can generate text (or pictures) that will be sent to your browser. The code generated by PHP XHTML via the echo () is nothing but text. If we take this for example:
Code:
<html xmlns= "http://www.w3.org/1999/xhtml" xml:lang= "fr" lang= "fr" >
<head >
<title> Here the title of your page </title>
<meta http-equiv= "Content-Type" content= "text/html; charset=iso-8859-1" />
<link rel= "stylesheet" href= "style.css" media= "screen" type= "text/css" />
</head>
<body>
<p> Hello! </p>
</body>
</html>
Bookmarks