PHP - Chapter 2 - Working With Text

Introduction

Printing text (such as status messages, static text fields, etc) is easy with PHP. There are many different ways to do so, but in this tutorial I will use the "echo" command. Type (or paste) the following code into a text editor and save the file as "script02.php" (without quotes). Upload the script to your server and navigate to the page URL to execute the script.

Definitions (in layman's terms)

String: An array of textual characters.

Code:
<html>
<head>
	<title>Working With Text in PHP</title>
</head>
<body>
	<?php
		echo("<p>Hello World!</p>");
	?>
</body>
</html>
Breakdown

The echo() statement is used to output a string. In the example above, the echo command will output the string: "<p>Hello World!</p>".

Since we have included the XHTML paragraph tags (<p> and </p>) which are interpreted by the browser, the only user readable information is "Hello World!". This means that any XHTML tags parsed to the browser through PHP are interpretted as XHTML! This is because PHP is a Hypertext Preprocessor.

< Back - Your First Script PHP Index Next - Comments >