If you decide to omit the closing PHP tag, then the last line of the file should be ended with semi colon. If you add the closing tag then last line doesn't need to end with semi colon.

<?php

echo "First line";
echo "Last line"

The above code throws error as it neither has closing tag nor semicolon ending. So it should be replaced with either of the below two

<?php
 
echo "First line";
echo "Last line";

or

<?php
echo "First line";
echo "Last line" ?>

Everything outside of  opening and closing tags is ignored by the PHP parser which allows PHP files to have mixed content. This allows PHP to be embedded in HTML documents, for example to create templates. 

<p>This is going to be ignored by PHP and displayed by the browser.</p>
<?php echo 'While this is going to be parsed.'?> 

<p>This will also be ignored by PHP and displayed by the browser.</p>

When the PHP interpreter hits the ?> closing tags, it simply starts outputting whatever it finds until it hits another opening tag unless in the middle of a conditional statement in which case the interpreter will determine the outcome of the conditional before making a decision of what to skip over. 

<?php if ($expression == true): ?> 
 This will show if the expression is true.
<?php else: ?> 

 Otherwise this will show.
<?php endif; ?>


In this example PHP will skip the blocks where the condition is not met, even though they are outside of the PHP open/close tags, PHP skips them according to the condition since the PHP interpreter will jump over blocks contained within a condition what is not met.
For outputting large blocks of text, dropping out of PHP parsing mode is generally more efficient than sending all of the text through echo or print.
 
When PHP parses a file, it looks for opening and closing tags, which are <?php and ?> which tell PHP to start and stop interpreting the code between them. Parsing in this manner allows PHP to be embedded in all sorts of different documents, as everything outside of a pair of opening and closing tags is ignored by the PHP parser. 

There are four different pairs of opening and closing tags which can be used in PHP. Two of those, <?php ?> and <script language="php"> </script>, are always available. The other two are short tags and ASP style tags, and can be turned on and off from the php.ini configuration file

 /* standard tags */
<?php 
echo 'if you want to serve PHP code in XHTML or XML documents,
                use these tags'
;

?>

// case insensitive 
<script language="php">
 echo 'some editors (like FrontPage) don\'t
              like processing instructions within these tags'
;

</script>

/* short tags, need short_open_tag enabled in php.ini*/
<?

echo 'this code is within short tags';
 ?>

// asp tags, need asp_tags enabled in php.ini 
<% 
 echo 'You may optionally use ASP-style tags';
%> 



Note: As per coding standards suggest to only use <?php ?> or <?= ?> 
PHP is a server-side scripting, so you can do anything any other CGI program can do, such as collect form data, generate dynamic page content, or send and receive cookies. 

There are three main areas where PHP scripts are used.  

1. Server-side scripting:
  
   You need three things to make this work. The PHP parser (CGI or server module), a web server and a web browser. You need to run the web server, with a connected PHP installation. You can access the PHP program output with a web browser, viewing the PHP page through the server. All these can run on your home machine if you are just experimenting with PHP programming.

2. Command line scripting:

   You can make a PHP script to run it without any server or browser. You only need the PHP parser to use it this way. This type of usage is ideal for scripts regularly executed using cron (on *nix or Linux) or Task Scheduler (on Windows). These scripts can also be used for simple text processing tasks.

3. Writing desktop applications: 

     PHP is probably not the very best language to create a desktop application with a graphical user interface, but if you know PHP very well, and would like to use some advanced PHP features in your client-side applications you can also use PHP-GTK to write such programs. You also have the ability to write cross-platform applications this way. PHP-GTK is an extension to PHP, not available in the main distribution.

PHP also has support for talking to other services using protocols such as LDAP, IMAP, SNMP, NNTP, POP3, HTTP, COM (on Windows) and countless others. You can also open raw network sockets and interact using any other protocol. PHP has support for the WDDX complex data exchange between virtually all Web programming languages. Talking about interconnection, PHP has support for instantiation of Java objects and using them transparently as PHP objects. 

PHP has useful text processing features, which includes the Perl compatible regular expressions (PCRE), and many extensions and tools to parse and access XML documents. PHP standardizes all of the XML extensions on the solid base of libxml2, and extends the feature set adding SimpleXML, XMLReader and XMLWriter support.

PHP will support for a wide range of databases. Writing a database-enabled web page is incredibly simple using one of the database specific extensions (e.g., for mysql), or using an abstraction layer like PDO, or connect to any database supporting the Open Database Connection standard via the ODBC extension. Other databases may utilize cURL or sockets, like CouchDB.
  
  • PHP, which stands for "PHP: Hypertext Preprocessor" is a open source scripting language that is especially suited for web development and can be embedded into HTML. 
  • The main goal of the language is to allow web developers to write dynamically generated web pages quickly.

Blog Archive

Total Pageviews

Popular Posts