PHP Syntax
A PHP script starts with <?php and ends with ?> :
<?php
// PHP code goes here
?>
Here is an example of a simple PHP file. The PHP script uses a built in function called "echo" to output the text "Hello World!" to a web page.// PHP code goes here
?>
<html>
<head>
<title>My First PHP Page</title>
</head>
<body>
<?php
echo "Hello World!";
?>
</body>
</html>
<head>
<title>My First PHP Page</title>
</head>
<body>
<?php
echo "Hello World!";
?>
</body>
</html>
PHP statements end with semicolons (;).
Alternatively, we can include PHP in the HTML <script> tag.
<html>
<head>
<title>My First PHP Page</title>
</head>
<body>
<script language="php">
echo "Hello World!";
</script>
</body>
</html>
<head>
<title>My First PHP Page</title>
</head>
<body>
<script language="php">
echo "Hello World!";
</script>
</body>
</html>
However, the latest version of PHP removes support for <script language="php"> tags. As such, we recommend using <?php ?> exclusively.
You can also use the shorthand PHP tags, <? ?>, as long as they're supported by the server.
<?
echo "Hello World!";
?>
echo "Hello World!";
?>
However, <?php ?>, as the official standard, is the recommended way of defining PHP scripts.
No comments:
Post a Comment