Discuss about structure of php

Post Views: 23

The server executes the PHP script, which will send the HTML output to the browser. Normally HTML and PHP tags can be present. A popular open source general programming language, PHP or Hypertext Preprocessor may be built into an HTML. The .php extension is used to store PHP files. In PHP tags, PHP scripts and standard HTML may be written in any page.

For beginners or pros alike, PHP is a pleasant language to use. We start working with PHP in this PHP Tutorial Series on the first floor. Even more experienced developers who need refreshment are very great to start from the start. Frequently you will realize that sophisticated difficulties are often a fairly fundamental mistake. That’s what makes the fundamentals so vital. They are the foundation for building on your whole understanding of programming. So let’s start getting our hands dirty with PHP today we look at what PHP is, and the history of this some times contentious language.

Examples:-

  • Author
  • Recent Posts

Tagged : Basic Structure / Basic Structure of PHP / How / Php / where / Why / with exeample

A PHP script is executed on the server, and the plain HTML result is sent back to the browser.

Basic PHP Syntax

A PHP script can be placed anywhere in the document.

A PHP script starts with :

The default file extension for PHP files is ".php".

A PHP file normally contains HTML tags, and some PHP scripting code.

Below, we have an example of a simple PHP file, with a PHP script that uses a built-in PHP function "echo" to output the text "Hello World!" on a web page:

Example



My first PHP page


Try it Yourself »

Note: PHP statements end with a semicolon [;].

PHP Case Sensitivity

In PHP, keywords [e.g. if, else, while, echo, etc.], classes, functions, and user-defined functions are not case-sensitive.

In the example below, all three echo statements below are equal and legal:

Example




Try it Yourself »

Note: However; all variable names are case-sensitive!

Look at the example below; only the first statement will display the value of the $color variable! This is because $color, $COLOR, and $coLOR are treated as three different variables:

Example




Try it Yourself »

PHP Exercises



The structure which defines PHP computer language is called PHP syntax.

The PHP script is executed on the server and the HTML result is sent to the browser. It can normally have HTML and PHP tags. PHP or Hypertext Preprocessor is a widely used open-source general-purpose scripting language and can be embedded with HTML. PHP files are saved with the “.php” extension. PHP scripts can be written anywhere in the document within PHP tags along with normal HTML. 
 

Escaping To PHP:

Writing the PHP code inside is called Escaping to PHP.

The mechanism of separating a normal HTML from PHP code is called the mechanism of Escaping To PHP. There are various ways in which this can be done. Few methods are already set by default but in order to use few others like Short-open or ASP-style tags, we need to change the configuration of the php.ini file. These tags are also used for embedding PHP within HTML. There are 4 such tags available for this purpose.

Canonical PHP Tags: The script starts with . These tags are also called ‘Canonical PHP tags’. Everything outside of a pair of opening and closing tags is ignored by the PHP parser. The open and closing tags are called delimiters. Every PHP command ends with a semi-colon [;]. Let’s look at the hello world program in PHP. 
 

PHP

Output: 

Hello, world!

SGML or Short HTML Tags: These are the shortest option to initialize a PHP code. The script starts with . This will only work by setting the short_open_tag setting in the php.ini file to ‘on’.  

Example: 
 

PHP

Output:

Hello, world!

HTML Script Tags: These are implemented using script tags. This syntax is removed in PHP 7.0.0.  So its no more used.  

Example: 
 

PHP

echo "hello world!";

 Output:

hello world!

ASP Style Tags: To use this we need to set the configuration of the php.ini file. These are used by Active Server Pages to describe code blocks. These tags start with

Example: 
 

PHP

Output:

hello world

Constants:

Constants can be defined using the const keyword or define[] function.

There is some difference between constants and variables.

  • Constants do not have $ in front of them like variables have.
  • Constants can be accessed from anywhere without regard to variable scoping rules.

Comments in PHP:

Comments help in reminding the developer about the code if it’s re-visited after a period of time.

A comment is something that is ignored and not read or executed by the PHP engine or the language as part of a program and is written to make the code more readable and understandable. These are used to help other users and developers to describe the code and what it is trying to do. It can also be used in documenting a set of codes or parts of a program. You must have noticed this in the above sample programs. 
PHP supports two types of comment: 
 

  • Single Line Comment: As the name suggests these are single line or short relevant explanations that one can add to their code. To add this, we need to begin the line with [//] or [#].

Example: 
 

PHP

Output: 
 

hello world!!!
  • Multi-line or Multiple line Comment: These are used to accommodate multiple lines with a single tag and can be extended to many lines as required by the user. To add this, we need to begin and end the line with [/*…*/
     

PHP

Output: 

hello world!

Case Sensitivity in PHP:

  • PHP is insensitive to whitespace. This includes all types of spaces that are invisible on the screen including tabs, spaces, and carriage returns. Even one space is equal to any number of spaces or carriage returns. This means that PHP will ignore all the spaces or tabs in a single row or carriage return in multiple rows. Unless a semi-colon is encountered, PHP treats multiple lines as a single command.

Example: 
 

PHP

Output:

45
45

Both of them show the same results without any errors.

  • PHP is case-sensitive. All the keywords, functions, and class names in PHP [while, if, echo, else, etc] are NOT case-sensitive except variables. Only variables with different cases are treated differently. Let’s look at this example: 
     

PHP

Output: 
 

25
25
25

Blocks in PHP:

In PHP, multiple statements can be executed simultaneously [under a single condition or loop] by using curly-braces [{}]. This forms a block of statements that gets executed simultaneously. 
 

PHP

Output: 
 

Positive as
greater than 0

This article is contributed by Chinmoy Lenka. If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to . See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
 


What is the structure of PHP?

PHP is an embedded scripting language when used in Web pages. This means that PHP code is embedded in HTML code. You use HTML tags to enclose the PHP language that you embed in your HTML file — the same way that you would use other HTML tags.

What is PHP explain in detail?

What is PHP? PHP is an acronym for "PHP: Hypertext Preprocessor" PHP is a widely-used, open source scripting language. PHP scripts are executed on the server. PHP is free to download and use.

What are the types of PHP syntax?

PHP supports four scalar types: bool , int , float , string ..
Boolean..
Integer..
Float..
String..
Array..
Object..
Callable..
Iterable..

What are the uses of PHP?

PHP [Hypertext Preprocessor] is known as a general-purpose scripting language that can be used to develop dynamic and interactive websites. It was among the first server-side languages that could be embedded into HTML, making it easier to add functionality to web pages without needing to call external files for data.

Chủ Đề