Earning sources

Recent online moneymaking guides.

Unlimited Music Library, No Fees. Raydiyo (spotify Killer)

Monday, 1 July 2013

PHP Tutorial: PHP Syntax overview

This chapter can offer you a plan of terribly basic syntax of PHP and extremely vital to create your PHP foundation robust.

Escaping to PHP:

The PHP parsing engine desires the way to differentiate PHP code from alternative components within the page. The mechanism for doing therefore is understood as 'escaping to PHP.' There area unit four ways in which to try to to this:

Canonical PHP tags:

The most universally effective PHP tag vogue is:
<?php...?>

If you utilize this vogue, you'll be positive that your tags can perpetually be properly understood.

Short-open (SGML-style) tags:

Short or short-open tags appear as if this:
<?...?>

Short tags area unit, joined may expect, the shortest choice you want to do one amongst 2 things to change PHP to acknowledge the tags:

Choose the --enable-short-tags configuration choice once you are building PHP.

Set the short_open_tag setting in your php.ini file to on. this feature should be disabled to analyse XML with PHP as a result of identical syntax is employed for XML tags.

ASP-style tags:

ASP-style tags mimic the tags employed by Active Server Pages to delineate code blocks. ASP-style tags appear as if this:
<%...%>
To use ASP-style tags, you may have to be compelled to set the configuration choice in your php.ini file.

HTML script tags:

HTML script tags appear as if this:
<script language="PHP">...</script>

Commenting PHP Code:

A comment is that the portion of a program that exists just for the human reader and stripped out before displaying the programs result. There area unit 2 commenting formats in PHP:

Single-line comments: they're usually used for brief explanations or notes relevant to the native code. Here area unit the samples of single line comments.
<?
# This is a comment, and
# This is the second line of the comment
// This is a comment too. Each style comments only
print "An example with single line comments";
?>

Multi-lines printing: Here area unit the examples to print multiple lines in a very single print statement:
<?
# First Example
print <<<END
This uses the "here document" syntax to output
multiple lines with $variable interpolation. Note
that the here document terminator must appear on a
line with just a semicolon no extra whitespace!
END;
# Second Example
print "This spans
multiple lines. The newlines will be
output as well";
?>

Paste your text here and click on "Next" to observe this text redactor do it's issue.

 don't have any text to cheMulti-lines comments: they're typically accustomed offer pseudo code algorithms and a lot of careful explanations once necessary. The multi line type of commenting is that the same as in C. Here square measure the instance of multi lines comments.ck? don't have any text to check? Click "Select Samples".
<?
/* This is a comment with multiline
    Author : Mohammad Mohtashim
    Purpose: Multiline Comments Demo
    Subject: PHP
*/
print "An example with multi line comments";
?>


PHP is whitespace insensitive:

White space is that the stuff you sort that's usually invisible on the screen, as well as areas, tabs, and carriage returns (end-of-line characters).

PHP white space insensitive implies that it virtually ne'er matters what percentage white space characters you've got during a row.one white space character is that the same as several such characters

For example, every of the subsequent PHP statements that assigns the total a pair of|of two} + 2 to the variable $four is equivalent:
$four = 2 + 2; // single spaces
$four <tab>=<tab2<tab>+<tab>2 ; // spaces and tabs
$four =
2+
2; // multiple lines

PHP is case sensitive:

Yeah it's true that PHP could be a case sensitive language. undertake following example:
<html>
<body>
<?
$capital = 67;
print("Variable capital is $capital<br>");
print("Variable CaPiTaL is $CaPiTaL<br>");
?>
</body>
</html>
This will bring the following result:
Variable capital is 67
Variable CaPiTaL is

Statements square measure expressions terminated by semicolons:

A statement in PHP is any expression that's followed by a punctuation mark (;).Any sequence of valid PHP statements that's cogitate by the PHP tags could be a valid PHP program. Here could be a typical statement in PHP, that during this case assigns a string of characters to a variable known as $greeting:

$greeting = "Welcome to PHP!";

Expressions area unit combos of tokens:

The smallest building blocks of PHP area unit the indiscreet tokens, like numbers (3.14159), strings (.two.), variables ($two), constants (TRUE), and therefore the special words that form up the syntax of PHP itself like if, else, while, for so forth

Braces create blocks:

Although statements can't be combined like expressions, will|you'll|you'll be able to} continually place a sequence of statements anyplace an announcement can pass introduction them in a very set of curly  braces.

Here each statements area unit equivalent:

if (3 == 2 + 1)
  print("Good - I haven't totally lost my mind.<br>");

if (3 == 2 + 1)
{
   print("Good - I haven't totally");
   print("lost my mind.<br>");
}

Running PHP Script from Command Prompt:

Yes you'll run your PHP script on your electronic communication. forward you've got following content in check.php file
<?php
   echo "Hello PHP!!!!!";
?>

Now run this script as electronic communication as follows:
$ php test.php

It will turn out following result:

Hello PHP!!!!!

Hope currently you've got basic information of PHP Syntax.





No comments:

Post a Comment

Adbox