Abstract PHP
Abstract PHP
Abstract
Almaty 2022.
PHP - Syntax Overview
Output in PHP
The PHP parsing engine needs a way to distinguish PHP code from other
elements on the page. The mechanism for this is known as "escape in
PHP". There are four ways to do this −
<?php...?>
If you use this style, you can be sure that your tags will always be interpreted
correctly.
<?...?>
Short tags are, as you would expect, the shortest option. In order for PHP to
recognize tags, you need to do one of two things:
Set short_open_tag in php.ini to on. This option must be disabled to parse XML
with PHP because the same syntax is used for XML tags.
To use ASP style tags, you need to set a configuration option in your php.ini file.
Single line comments - These are typically used for brief explanations or notes
relating to local code. Here are examples of single line comments.
<? # This is a comment, and # This is the second line of the comment
// This is a comment too. Each style comments only print "An example with
single line comments" ; ?>
Multiline printing. Here are examples of printing multiple lines in one print
statement.
<? # First Example print <<< END This uses the "here document" syntax to
output
For example, each of the following PHP statements, which assigns the sum of 2 +
2 to the variable $four, is equivalent to −
live demo
<html> <body>
<? php
$capital = 67 ; print ( "Variable capital is $capital<br>" ); print ( "Variable
CaPiTaL is $CaPiTaL<br>" ); ?>
</body> </html>
Variable capital is 67
Variable CaPiTaL is
if (3 == 2 + 1)
print("Good - I haven't totally lost my mind.<br>");
if (3 == 2 + 1) {
print("Good - I haven't totally");
print("lost my mind.<br>");
}
live demo
<?php
echo "Hello PHP!!!!!";
?>
$phptest.php