Embedding php is pretty easy.One basic advantage of PHP is the it can be embedded alongside HTML. For the code to do anything, you just need to pass it through a php engine for interpretation.
The default syntax contain php code starting from
and ends with
?> . Every php statement ends with a delimiter ';'.
<h3>Welcome</h3> <?php echo "Some dynamic code"; ?> <p>Some static code</p>
echo is similar to a print statement.
Though less motivated, a php code can be wriiten as
<? echo "php code"; ?>
Caution: Short tags delimiters should not be used while making a php driven software intended to redistribution.
Another way for embedding php in your code is using srcipt
<script language="php"> print "This is another php example"; </script>
Microsoft ASP provides a similar delimiting strategy as used by php. The delimiting strategy forms a specific pattern, starting the dynamic code using <% and closing the dynamic code using %>
<% print" another php code"; %>
Caution:This ASP style is no longer used form PHP 5.3.
Embedding multiple code blocks
You can use multiple php codes in a single page.For instance see this code:
<head> <title><?php echo "i am title"; ?></title> </head> <body> <h3>welcome</h3> <?php echo "hii"; ?> <p>some text goes here </p> <?php echo "php again"; ?> </body>
Commenting on your code
Single line comment
Comment often do not require more than a single line.PHP supports C++ single line comment preface by a double slashed (//).
<?php //title:hello echo "code"; ?>
PHP also supports C++ shell syntax in comments, using (#)
<?php #title:hello echo "code"; ?>
Multi line comments
PHP also supports multi line comments as same C++. The multi line comments begin with (/*) and end with (*/). This block can have many lines of comment.
<?php /* hi i am a multi line comment I can hold many line comment more */ echo "code"; ?>