Writing PHP Scripts

PHP scripts are plain text files that may contain a mixture of HTML and PHP code. The script is interpreted to produce a Web page as output that is sent to the client. The HTML is copied to the output without interpretation. PHP code is interpreted and replaced by whatever output the code produces (possibly none).

PHP begins interpreting a file in HTML mode. You can switch into and out of PHP code mode using special tags that signify the beginning and end of PHP code. You can switch between modes any number of times within a file. PHP understands four types of tags, although some of them must be explicitly enabled if you want to use them. One way to do this is by turning them on in the PHP initialization file, php3.ini. The location of this file is system dependent; it's often found in /usr/local/lib.

PHP understands the following tag styles:

  • The default style uses '<?php' and '?>' tags:


    <?php echo ("Some PHP code here"); ?>
  • Short-open-tag style uses '<?' and '?>' tags:


    <? echo ("Some PHP code here"); ?>

    This tag style can be enabled with a directive in the PHP initialization file:


    short_open_tag = On;
  • Active Server Page-compatible style uses '<%' and '%>' tags:


    <% echo ("Some PHP code here"); %>

    ASP-style tags can be enabled with a directive in the PHP initialization file:


    asp_tags = On;

    Support for ASP tags was introduced in PHP 3.0.4.

  • If you use an HTML editor that doesn't understand the other tags, you can use <SCRIPT> and </SCRIPT> tags:


    <SCRIPT LANGUAGE="php"> echo ("Some PHP code here"); </SCRIPT>
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.23.101.60