• Skip to main content
  • Skip to primary sidebar
  • Skip to secondary sidebar
  • Skip to footer

Computer Notes

Library
    • Computer Fundamental
    • Computer Memory
    • DBMS Tutorial
    • Operating System
    • Computer Networking
    • C Programming
    • C++ Programming
    • Java Programming
    • C# Programming
    • SQL Tutorial
    • Management Tutorial
    • Computer Graphics
    • Compiler Design
    • Style Sheet
    • JavaScript Tutorial
    • Html Tutorial
    • Wordpress Tutorial
    • Python Tutorial
    • PHP Tutorial
    • JSP Tutorial
    • AngularJS Tutorial
    • Data Structures
    • E Commerce Tutorial
    • Visual Basic
    • Structs2 Tutorial
    • Digital Electronics
    • Internet Terms
    • Servlet Tutorial
    • Software Engineering
    • Interviews Questions
    • Basic Terms
    • Troubleshooting
Menu

Header Right

Home » PHP » PHP Tutorials

Why it is not advisable to use short tags …

By Dinesh Thakur

As you all know, any PHP script must be surrounded by specific tags. These reserves allow the interpreter to know where in the file is PHP code to execute. On ecomputernotes.com, all presented scripts use the <? Php and?>; and it is not by chance …

The differentPHP codeboundary markers

• <?php and ?> (formal language tags)
• <? and ?> (very short tags used by novice webmasters)
• <? = And ?> (Rarely used)
• <% And %> (tag from the ASP language – rarely used)
• <script language = “php”> and </script?> (rarely used)

Why prefer <?php and ?>?

Simply because the tags <?php and ?> Ensure full portability on all servers and all versions of PHP. These are the tags default PHP.

However, “short-tags” could prevent the execution of your scripts for the following two reasons:

• The server that hosts your php pages disables the use of these tags with the short_open_tags php.ini directive placed to off.
• There continues to be confusion with the opening tag of an XML file.

In fact, an XML file begins with the following syntax:

An XML file

<? Xml version = "1.0" encoding = "utf-8" standalone = "yes"?> 

Note the presence of the short tag <? at the beginning of the code and?> at the end. When reading the file, the interpreter PHP will attempt to execute this line (thinking it’s PHP) and return a parsing error similar to the one below:

Syntax error: conflict between the interpreter and the PHP XML file

• Parse error: syntax error, unexpected T_STRING in /Applications/MAMP/htdocs/Tests-PHP/xml.php on line 1 

 

The only way to solve this problem is to generate the XML code using a PHP echo () statement for example.

Solution to avoid conflict

<?php
echo '<? xml version = "1.0" encoding = "utf-8" standalone = "yes"?> "," \ n ";
  ?>

 

I will not change my files still …

 

If you do not intend to change provider, then do not change all your scripts but cons think to adopt this good practice for future applications. You are not
immune to a different configuration of a server (that of a customer for example).

Note for example that the default software EasyPHP.2 banned short tags to force developers to adopt this good practice.

PHP First program: the traditional “Hello World display …

By Dinesh Thakur

In previous tutorials on working environments, we have shown that PHP is a dynamic scripting language interpreted and precompiled server side. It is now for us to achieve our first programs and run them on the web server (local or remote).

In computer programming, there is a “tradition” which is to generate the string (note the term the way) Hello World! standard output (in our case it is a computer screen). Let’s start with the first script shown below.

First PHP script

Enter the following code in a text editor (Note pad, Wordpad or Notepad ++ are largely the case) then save the file with the name helloworld.php.

Note: all files containing PHP code are required to be registered with the .php extension (or .phpX where X is the PHP version number).

First PHP program: “Hello World”

<?php echo 'Hello World!'; ?> 

Run this first script in a web browser (Safari, Firefox, Opera, Internet Explorer …). You see that the text Hello World! appears well on screen. So we get the desired result out. Time to explanations.

Code Explanation

First of the beacons. Any PHP script must be surrounded by two tags to delimit the other type of content contained in a single file (eg HTML). Here we use the <? Php and?>. There are others but they are strongly advised not to use. If you want to know what are they and why we should not use them, please see the following tutorial: Why it is not advisable to use short tags (short-tags)?.

Regardless, you should always use the markers of this first program. This is THE first good practice to adopt when you code in PHP.

The second part of the code is what is called a programming instruction. The echo () function (or rather the language structure because it is a particular function of PHP) is responsible for writing what is happening as a parameter to standard output. Here the setting is a string (type) whose value is “Hello World! “.

Important concept to remember: the PHP script is executed on the server and the result of this execution being returned (here the html code) is interpreted by the Web browser.

Improved Hello World

So far nothing difficult. Let us move to the next level. We will generate our Hello World! in the middle of an HTML document. Here the file code helloworld1.php:

 

Generating a minimal HTML document

<! DOCTYPE html PUBLIC "- // W3C // DTD XHTML 1.1 // EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml" xml: lang = "en">
      <head>
           <title> First PHP program! </title>
      </head>
             <body>
                  <?php
                        echo 'Hello World!';
                     ?>
             </body>
</html>

First PHP program!

After running this file, we see that the result on screen is exactly the same as before. Yes, but only to the naked eye! Here we generated our string inside HTML. The principle of dynamic page begins to be felt from there. Indeed, PHP will allow us to generate pages from templates and parameters provided to it.

Suppose we want to display our Hello World! in bold. Two choices are available to us:

We place the <strong> and </strong> on either side of the script.
We place the <strong> and </strong> directly in the echo () statement.

Whatever the result is the same product. But the second example (see code below) shows while it is possible to generate HTML code to build a page. The advantage of PHP becomes evident and we can imagine all the possibilities available to us later. For example: generate HTML tables, lists, links, paragraphs, XML documents …

 

A “Hello World” in bold

<! DOCTYPE html PUBLIC "- // W3C // DTD XHTML 1.1 // EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml" xml: lang = "en">
          <head>
                 <title> First PHP program! </title>
         </head>
                <body>
                     <?php
                             echo '<strong> Hello World </strong>';
                        ?>
                </body>
</html>

 

The code below will effectively write on the screen: Hello World!

How to install and handle MAMP on your MacOS

By Dinesh Thakur

In order to work with PHP, we must ensure that the prerequisites necessary for the implementation of programs. In the development context of web  applications, a web server with PHP is mandatory. The MAMP software (short for Macintosh, Apache, MySQL and PHP) will launch a local web server on a machine  running on the Mac OS X. It is a software for brand users with apple and which contains the following free components: Apache (server daemon), PHP5, MySQL  (DBMS, SQLite (DBMS), and PHPMyAdmin SQLiteManage (administration tools BDD).

We will show in this course how to install this software on Mac OS and use it for our first PHP applications.

Download MAMP Software

The first thing is of course to download MAMP software from the official website of MAMP at http://www.mamp.info/.

Download MAMP for MacOS

MAMP is available for Macintosh equipped with Motorola PowerPC or Intel chip.

Installing MAMP

After unzipping the Zip archive disk image (.dmg file). It is the installer software.

          MAMP Installer Dialog

Just do a “drag and drop” the MAMP folder window and drop it into the Applications directory thereof. That’s it MAMP is installed correctly. We note the MAMP folder (fitted gray logo) in the Applications directory MacOS (shortcut Command + Shift + A).

                                               Drag MAMP folder to Application folder

First start of the software

The launch of MAMP is done by clicking on the icon MAMP.app. A new window launches.

                                MAMP Control Window

This window allows you to control the web server (Apache) and database server (MySQL) have been launched. The green lights show a good operation. The Preferences tab allows you to configure MAMP.

The modifiable parameters are for example the ports behind which the server processes or the working directory where the projects are located (eg websites).

                                  MAMP Port Setting

It is recommended that the configuration imposed by MAMP for people without sufficient computer knowledge.

The startup MAMP also involves opening a new window in the web browser (Safari by default). This is the home page of MAMP. It also attests to the proper functioning of the local Web server.

                MAMP Home Page

Note first that to access the local web server, we use the URL http: // localhost: 8888 / MAMP. The localhost can be replaced with the IP address 127.0.0.1. The Web server listens for the LAN information on port 8888. Port 80 is reserved by default to the Web through the Internet.

The menu at the top provides access to phpinfo () (PHP configuration), utilities database management (PHPMyAdmin and SQLiteManager) as well as to a performance optimization PHP application (eAccelerator).

The important directories MAMP

The six important directories of MAMP are:

• / bin: directory containing executable Apache, PHP4, PHP5, MySQL5 and SQLite.
• / conf: directory containing Apache configuration file (httpd.conf), PHP (php.ini) and SQLiteManager (config.db).
• / tmp: directory containing the temporary files created by the executables. The / tmp / php include contains temporary files of PHP sessions.
• / db: directory containing MySQL5 and SQLite databases.
• / logs: directory containing the files of PHP error logs, Apache and MySQL.
• / htdocs: directory containing various website projects.

PHP first test

We will test our first PHP application: the traditional “hello world”. For this, we first create a new directory called PHP-Code in the / htdocs.

Then we put in this directory a file named hello.php that contains the following code:

Listing of hello.php: first PHP program

<html>
        <head>
               <title> Hello World PHP </title>
        </head>
                <body>
                      <p>
                             <?php echo 'Hello World!'; ?>
                      </p>
                </body>
</html>

 

In our browser, we call the file by entering the following URL: http: // localhost: 8888 /PHP-Code/hello.php. The PHP script is executed and displayed on the screen the text Hello World!. So PHP works perfectly.

Database managers: PHPMyAdmin and SQLiteManager

PHPMyAdmin

The free utility PHPMyAdmin is located at the following address: http: // localhost: 8888 / phpMyAdmin /. It allows to manage databases and tables MySQL SQL type.

                    mamp phpmyadmin

We return to this application when next tutorielss requiring the use of MySQL databases.

SQLiteManager

The free utility SQLiteManager is located at the following address: http: // localhost: 8888 / SQLiteManager /. It allows to manage databases and SQL tables SQLite.

                     MAMP SQLLite

We will return to this application at upcoming tutorials require the use of SQLite databases.

MAMP widget

                                                 

MAMP also offers a small widget to place in the Dashboard MacOS. This allows to monitor the status of Web servers and SQL; and restart them if necessary.

By clicking on the little exclamation point, it is possible to switch to 1 second PHP5 to PHP4. This is handy when you want to test the compatibility of an application.

Features of the PHP language

By Dinesh Thakur

License

PHP is first an interpreted scripting language (actually precompiled opcodes), free, open source and distributed under a license authorizing the modification and redistribution. [Read more…] about Features of the PHP language

Introduction to PHP

By Dinesh Thakur

PHP was invented by Rasmus Lerdorf in 1994 for his own use (posting his resume in this case). Formerly abbreviation for Personal Home Page now become Hypertext Preprocessor, PHP is becoming a standard in the world of web programming with its performance, reliability, flexibility and speed.

Birth of this language

PHP was born in 1994 of a Perl program written by Rasmus Lerdorf to analyze visits his online resume. It rewrites the C language application and then opens its program to the free software community. Thus, he can now count on the help of many developers. His PHP application merges with an engine forms processing, FI, giving version 2. With version 3, the functions become numerous and popularity grows.

Language Evolution

The PHP language has evolved yet. We are currently in PHP 6. Users are not forced to take the train every technical advance for several reasons:

• Many production sites are made in PHP 3 or PHP 4 and work very well;

• Web hosts often offer PHP 4 configuration; the object language requires a more elaborate reasoning. Several reasons can grow to change the version:

• A platform or framework passes this version and we are interested; by challenge and desire to learn new syntax or frameworks.

Interest in this language

PHP is free, portable and easy to understand. It is a language for everyone. This is not an esoteric language intended only for professionals, with an incomprehensible jargon. Some called complex languages are fashionable because of their complexity allows businesses to spend much time on expensive applications paid. PHP is flexible, robust and fast for interested professionals and wealth of tools will make in the coming years, the preferred language of all companies.

Freedom

PHP is free. Thus, most free hosts offer it with the MySQL database, free too. Free also means that anyone can enrich provided to benefit everyone graciously. Within the free software community, licenses disclaim separate copyright. Indeed, free does not mean that anything goes or that everything is free.

The PHP language is constantly evolving thanks to a community of approximately 200 developers. The documentation is continuously updated and thousands of sites around the world devote themselves by publishing articles, forums, tips or offering free applications. PHP is carried by a wave of popularity that continues to grow.

Portability

PHP can run on any machine. The programs you create are executable on Unix, Linux, Windows or Macintosh. This feature frees you of decisions made by Microsoft or Apple and secures the future of your application.

The facility

PHP can be addressed by all. First, it’s free and continuously enriched by many developers (about 200). On the other hand, it is simple to start programming in PHP. All this plays a great role in its popularity. The fact that it is supported by a large number of developers ensures a continuous evolution and promotes the integration of the latest developments in computer language.

The language is simple. You start immediately and get a result. This allows everyone to learn at their own pace and integrate the knowledge of the functions and extensions to suit his desires.

A little history

The PHP language is derived mainly from the Perl language; it is therefore based on the string type, or string. The string in English is the thread of a pearl necklace. In the C language, which is the ancestor of most languages currently in use, there is no string type. Only the characters exist as A or B. A sentence is then an array of characters with the first character in the first box and the number 0 in the last box, to complete the chain. A string is a string of characters, which is quite far from the way we see the words that are real units of language. Perl was designed to simplify the rules that governed the writing of programming languages. The idea was to bring writing code natural language that is to say how the human is expressed. The Perl language gave birth to the PHP language while other languages have taken other routes.

PHP, Perl from its base and C, borrowed object-oriented design in Java (in version 3). The main purpose of an object language is the reuse of autonomous and portable programming blocks in several programs. This language is derived from C ++ code. The approach Java developers follows the same conclusion: the C ++ language is heavy to handle, it was necessary to simplify and secure the use. Designers create the Java language under the aegis of Sun Microsystems. The Java code does not have the flexibility of PHP language, so a piece of PHP language program that takes fifteen minutes to design and write request over an hour in Java. Java programmers say that the PHP language is a language of “hack”. One can actually do everything and anything. What PHP programmers take as a compliment? Both languages tend to approach, at least, PHP can now, through libraries, use Java classes. PHP is mixed of all these cultures.

 We will not have the place to address the aspect of the object programming language PHP. By cons, in the articulation of PHP files (application architecture), we will draw the object programming. Then you can tune to learn the syntax PHP and practice to master this aspect of language. Version 5 of PHP will develop this aspect. The feature of the PHP language is to keep backward compatibility. Thus, some functions have changed names but the old name is still operational. All this is a polymorphic language PHP language. We will compare it to an encyclopedia. For each problem posed, there are several approaches. You can use whatever works from the time where you keep consistency and rigor. Remember indeed to be rigorous because PHP does not require you to follow the beaten track.

Operation

PHP core is a C language motor located on the server. When a file is called a web browser, according to its extension (.htm, .php, .asp …), the server sends it directly to the browser to display the page or treats (in the case of a .php file) by running the commands of the PHP language, the result is returned as HTML code.

PHP is interpreted in its version 3 and compiled on the fly in version 4. The compiled language is a little faster for the machine.

« Previous Page

Primary Sidebar

PHP Tutorials

PHP Tutorials

  • PHP - Home
  • PHP - Features
  • PHP - Magic Methods
  • PHP - Imagefilter
  • PHP - Arrays Numeric
  • PHP - Sessions
  • PHP - Forms Processing
  • PHP - clone()
  • PHP - Cookies
  • PHP - Variable Types
  • PHP - First program
  • PHP - call()
  • PHP - Iterator interface
  • PHP - Imports files
  • PHP - Exception Handling
  • PHP - set() and get()
  • PHP - Install MAMP
  • PHP - Functions
  • PHP - Constants Types
  • PHP - Comments Types
  • PHP - OOP's
  • PHP - OOps Use
  • PHP - PHP Code & Redirect 301
  • PHP - Control structures
  • PHP - Abstract Classes
  • PHP - Control structures
  • PHP - Classes
  • PHP - MySQL NULL values
  • PHP - Methods Visibility
  • PHP - Operator Types
  • PHP - Short tags Not use
  • PHP - Object and class
  • PHP - Secure Passwords

Other Links

  • PHP - PDF Version

Footer

Basic Course

  • Computer Fundamental
  • Computer Networking
  • Operating System
  • Database System
  • Computer Graphics
  • Management System
  • Software Engineering
  • Digital Electronics
  • Electronic Commerce
  • Compiler Design
  • Troubleshooting

Programming

  • Java Programming
  • Structured Query (SQL)
  • C Programming
  • C++ Programming
  • Visual Basic
  • Data Structures
  • Struts 2
  • Java Servlet
  • C# Programming
  • Basic Terms
  • Interviews

World Wide Web

  • Internet
  • Java Script
  • HTML Language
  • Cascading Style Sheet
  • Java Server Pages
  • Wordpress
  • PHP
  • Python Tutorial
  • AngularJS
  • Troubleshooting

 About Us |  Contact Us |  FAQ

Dinesh Thakur is a Technology Columinist and founder of Computer Notes.

Copyright © 2025. All Rights Reserved.

APPLY FOR ONLINE JOB IN BIGGEST CRYPTO COMPANIES
APPLY NOW