How to Identify PHP Protocol

When a Web server runs a PHP script, or serves an HTML Web page with snippets of PHP code interspersed throughout the page, the server must be able to identify the parts of the script or page that use the PHP protocol. When the server encounters the tags that identify a piece of PHP code, it will parse the code and output the results to the browser or system memory, as instructed by the script.

Things You'll Need

  • Text editor
  • FTP connection or other file uploader
Show More

Instructions

    • 1

      Identify the PHP protocol within your script or Web page by enclosing the code in the proper opening and closing tags.

      The standard, most widely used opening tag consists of a "less than" sign, a question mark and the letters "php." The corresponding closing tag consists of a question mark followed by a "greater than" sign. Thus, a simple echo statement contained in standard opening and closing PHP tags would look like this:

      <?php
      echo "Hello, World!";
      ?>

    • 2

      When authoring dynamic Web pages with server-side code interspersed with HTML, you can alternately enclose your PHP code within a <script> element, in much the same way that you would for a piece of JavaScript code. Set the "language" attribute of your <script> element to "php." It is not necessary to specify the "type" attribute. This method involves several more keystrokes than the standard tag, but may be necessary to avoid conflicts with some Web page creation software:

      <script language="php">
      echo "I hope you are well.";
      </script>

    • 3

      In some server environments, the php.ini file may be configured to allow short tags:
      <?
      echo "Good morning.";
      ?>
      In special cases, the server may be configured to parse code as PHP when it is demarcated by ASP-style tags:

      <%
      echo "This block of PHP code is contained within ASP-style tags.";
      %>

      However, since short tags and ASP-style tags are not supported by all servers, the standard tags are recommended to ensure maximum portability. Additionally, PHP short tags look just like the tags used for XML declaration, which can lead to incompatibility, parse errors and general confusion.

    • 4

      When you know that your script will only ever be used as an included file within a calling script, you may omit the closing PHP tag. However, be judicious in your omission of closing tags, because if you have HTML and PHP on the same page and omit the closing tag, this will result in a parse error.
      In general, it is best practice to always identify PHP code by wrapping it in the <?php ?> opening and closing tags.

Tips & Warnings

  • Global settings for how PHP is parsed can be changed by modifying php.ini; however, in many shared hosting environments, system administrators do not allow access to this file.

  • If your server has PHP short tags enabled, you will need to convert any XML declarations in your Web pages into PHP echo statements to avoid parse errors. For example:

  • <?php echo '<?xml version="1.0" encoding="utf-8" ?>'; ?>

Related Searches:

References

Comments

You May Also Like

  • Layer Three Protocols

    Routing protocols are best thought of as the language computers and routers use to speak to one another. The term "layer three...

  • How to Create a TCP/IP Connection With PHP

    You can use PHP to create a two-way communication over TCP/IP between two computers. This is helpful when extra information needs to...

  • How to Identify File Protocol

    The File Transfer Protocol (FTP) is a service used to transfer and store files on a server. FTP servers are used to...

  • What Is Rest Protocol?

    When publishers create websites, they provide a way for the content on their web pages to be accessed. REST, or Representational State...

  • Video File Transmission Protocol

    The central file transmission protocol of the Internet is the File Transfer Protocol, or FTP. This transfers all types of files, including...

  • How to Identify the Communications Protocol

    Every organization has a communications protocol. Whether it is identified or not, one exists. Many developed organizations have their communications protocol ...

  • How to Identify Frogs

    When it comes to pet ownership, reptile owners are a different breed. Choosing the cool and slithery takes a special person. Frogs...

  • How to Change PHP or ASP.NET version with enom web hosting

    With eNom's Web Hosting you have the ability to mix and match php4 and php5, as well as asp.Net 1.1 and 2.0...

  • How to Find XML Encoding

    Extensible Markup Language (XML) is an encoding standard that lets website programmers display data from a database. XML must be denoted using...

  • How to Use cURL to Read a File in a Variable PHP

    Client Uniform Resource Locator (cURL) is a command line tool and library (libcurl) for transferring files over a network. cURL supports most...

  • How to Track an IP Address in PHP

    Tracking Internet Protocol (IP) addresses of your web visitors is an important technique for validating sessions and gathering useful data about your...

  • Why Use a Protocol Analyzer?

    Protocol analysis is the process network administrators and troubleshooters use to monitor the health of their networks, discover performance problems, and on...

  • LDAP Security Protocol

    LDAP stands for Lightweight Directory Access Protocol. It is used for Network Information Services (NIS). NIS systems store common configuration details for...

  • How to Identify Internet Scams

    Internet scams can be extremely dangerous to you and your identify. They can be difficult to identify as well, which makes them...

  • Web Config Protocol

    Web configuration protocols include five elements to enable communication between Web browsers and websites. They are internationally accepted control codes that tell...

  • Java Script Vs. PHP

    Javascript and PHP allow website developers to create dynamic Web pages. Javascript is a client-side language, so it runs on the reader's...

  • How to Upload PHP Files to a Server

    PHP is a server-side scripting language that is embedded in your web site’s HTML to make the site more dynamic and responsive...

  • How to Use SSL Combined With a PHP Redirect

    Information security is an essential part of keeping the Internet useful, and it's up to everyone to keep it secure. One important...

  • The SOAP Access Protocol

    Simple Object Access Protocol (SOAP) is a standard for messaging structures. These messages are passed between dissimilar applications over a network. The...

Related Ads

Featured