php 5 syntax

2
REFERENCES | EXAMPLES | FORUM | ABOUT PHP Tutorial PHP HOME PHP Intro PHP Install PHP Syntax PHP Variables PHP Echo / Print PHP Data Types PHP String Functions PHP Constants PHP Operators PHP If...Else...Elseif PHP Switch PHP While Loops PHP For Loops PHP Functions PHP Arrays PHP Sorting Arrays PHP Superglobals PHP Forms PHP Form Handling PHP Form Validation PHP Form Required PHP Form URL/E-mail PHP Form Complete PHP Advanced PHP Arrays Multi PHP Date and Time PHP Include PHP File Handling PHP File Open/Read PHP File Create/Write PHP File Upload PHP Cookies PHP Sessions PHP E-mail PHP Secure E-mail PHP Error PHP Exception PHP Filter PHP Database PHP MySQL Intro PHP MySQL Connect PHP CREATE DB/Table PHP INSERT INTO PHP SELECT PHP WHERE PHP ORDER BY PHP UPDATE PHP DELETE PHP ODBC PHP XML XML Expat Parser XML DOM XML SimpleXML PHP and AJAX AJAX Intro AJAX PHP AJAX Database AJAX XML AJAX Live Search AJAX RSS Reader AJAX Poll PHP Examples PHP Examples PHP Quiz PHP Certificate PHP Reference PHP Array PHP Calendar PHP Date PHP Directory PHP Error PHP Filesystem PHP Filter PHP FTP PHP HTTP « Previous Next Chapter » PHP 5 Syntax The 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 <?php and ends with ?>: <?php // PHP code goes here ?> 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 <!DOCTYPE html> <html> <body> <h1>My first PHP page</h1> <?php echo "Hello World!"; ?> </body> </html> Run example » Note: PHP statements are terminated by semicolon (;). The closing tag of a block of PHP code also automatically implies a semicolon (so you do not have to have a semicolon terminating the last line of a PHP block). Comments in PHP A comment in PHP code is a line that is not read/executed as part of the program. Its only purpose is to be read by someone who is editing the code! Comments are useful for: To let others understand what you are doing - Comments let other programmers understand what you were doing in each step (if you work in a group) To remind yourself what you did - Most programmers have experienced coming back to their own work a year or two later and having to re-figure out what they did. Comments can remind you of what you were thinking when you wrote the code PHP supports three ways of commenting: Example <!DOCTYPE html> <html> <body> <?php // This is a single line comment # This is also a single line comment /* This is a multiple lines comment block that spans over more than one line */ ?> </body> </html> Run example » PHP Case Sensitivity In PHP, all user-defined functions, classes, and keywords (e.g. if, else, while, echo, etc.) are NOT case-sensitive. In the example below, all three echo statements below are legal (and equal): Search w3schools.com: WEB HOSTING Best Web Hosting UK Reseller Hosting Dedicated Servers cPanel Hosting WEB BUILDING XML Editor - Free Trial! FREE Website BUILDER Free HTML5 Templates W3SCHOOLS EXAMS HTML, CSS, JavaScript, PHP, jQuery, XML, and ASP Certifications SHARE THIS PAGE WEB RESOURCES Web Statistics Web Validation HOME HTML CSS JAVASCRIPT SQL PHP JQUERY XML ASP.NET MORE... Select Language PHP 5 Syntax 28/05/2014 http://www.w3schools.com/php/php_syntax.asp 1 / 2

Upload: masterpatel

Post on 23-Nov-2015

3 views

Category:

Documents


0 download

DESCRIPTION

PHP 5 Syntax

TRANSCRIPT

  • REFERENCES | EXAMPLES | FORUM | ABOUT

    PHP TutorialPHP HOMEPHP IntroPHP InstallPHP SyntaxPHP VariablesPHP Echo / PrintPHP Data TypesPHP String FunctionsPHP ConstantsPHP OperatorsPHP If...Else...ElseifPHP SwitchPHP While LoopsPHP For LoopsPHP FunctionsPHP ArraysPHP Sorting ArraysPHP Superglobals

    PHP FormsPHP Form HandlingPHP Form ValidationPHP Form RequiredPHP Form URL/E-mailPHP Form Complete

    PHP AdvancedPHP Arrays MultiPHP Date and TimePHP IncludePHP File HandlingPHP File Open/ReadPHP File Create/WritePHP File UploadPHP CookiesPHP SessionsPHP E-mailPHP Secure E-mailPHP ErrorPHP ExceptionPHP Filter

    PHP DatabasePHP MySQL IntroPHP MySQL ConnectPHP CREATE DB/TablePHP INSERT INTOPHP SELECTPHP WHEREPHP ORDER BYPHP UPDATEPHP DELETEPHP ODBC

    PHP XMLXML Expat ParserXML DOMXML SimpleXML

    PHP and AJAXAJAX IntroAJAX PHPAJAX DatabaseAJAX XMLAJAX Live SearchAJAX RSS ReaderAJAX Poll

    PHP ExamplesPHP ExamplesPHP QuizPHP Certificate

    PHP ReferencePHP ArrayPHP CalendarPHP DatePHP DirectoryPHP ErrorPHP FilesystemPHP FilterPHP FTPPHP HTTP

    Previous Next Chapter

    PHP 5 Syntax

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

    Basic PHP SyntaxA 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 thetext "Hello World!" on a web page:

    Example

    My first PHP page

    Run example

    Note: PHP statements are terminated by semicolon (;). The closing tag of a block of PHP code also automatically implies asemicolon (so you do not have to have a semicolon terminating the last line of a PHP block).

    Comments in PHPA comment in PHP code is a line that is not read/executed as part of the program. Its only purpose is to be read bysomeone who is editing the code!

    Comments are useful for:

    To let others understand what you are doing - Comments let other programmers understand what you were doing ineach step (if you work in a group)To remind yourself what you did - Most programmers have experienced coming back to their own work a year or twolater and having to re-figure out what they did. Comments can remind you of what you were thinking when youwrote the code

    PHP supports three ways of commenting:

    Example

    Run example

    PHP Case SensitivityIn PHP, all user-defined functions, classes, and keywords (e.g. if, else, while, echo, etc.) are NOT case-sensitive.

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

    Search w3schools.com:

    WEB HOSTINGBest Web Hosting

    UK Reseller HostingDedicated Servers

    cPanel Hosting

    WEB BUILDINGXML Editor - Free Trial!FREE Website BUILDERFree HTML5 Templates

    W3SCHOOLS EXAMSHTML, CSS, JavaScript,PHP, jQuery, XML, and

    ASP Certifications

    SHARE THIS PAGE

    WEB RESOURCESWeb StatisticsWeb Validation

    HOME HTML CSS JAVASCRIPT SQL PHP JQUERY XML ASP.NET MORE...

    Select Language

    PHP 5 Syntax 28/05/2014

    http://www.w3schools.com/php/php_syntax.asp 1 / 2

  • PHP LibxmlPHP MailPHP MathPHP MiscPHP MySQLiPHP SimpleXMLPHP StringPHP XMLPHP ZipPHP Timezones

    Previous Next Chapter

    Example

    Run example

    However; in PHP, all variables are case-sensitive.

    In 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

    Run example

    REPORT ERROR | HOME | TOP | PRINT | FORUM | ABOUT | ADVERTISE WITH US

    Top 10 Tutorials

    HTML Tutorial HTML5 Tutorial CSS Tutorial CSS3 Tutorial JavaScript Tutorial jQuery Tutorial SQL Tutorial PHP Tutorial ASP.NET Tutorial XML Tutorial

    Top 10 References

    HTML/HTML5 Reference CSS 1,2,3 Reference CSS 3 Browser Support JavaScript HTML DOM XML DOM PHP Reference jQuery Reference ASP.NET Reference HTML Colors

    Top 10 Examples

    HTML Examples CSS Examples JavaScript Examples HTML DOM Examples PHP Examples jQuery Examples XML Examples XML DOM Examples ASP Examples SVG Examples

    Web Certificates

    HTML Certificate HTML5 Certificate CSS Certificate JavaScript Certificate jQuery Certificate XML Certificate ASP Certificate PHP Certificate

    Color Picker

    W3Schools is optimized for learning, testing, and training. Examples might be simplified to improve reading and basic understanding. Tutorials, references, and examplesare constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using this site, you agree to have read and accepted our terms of use,

    cookie and privacy policy. Copyright 1999-2014 by Refsnes Data. All Rights Reserved.

    PHP 5 Syntax 28/05/2014

    http://www.w3schools.com/php/php_syntax.asp 2 / 2

    PHP TutorialWEB HOSTINGPHP 5 SyntaxWEB BUILDINGBasic PHP SyntaxW3SCHOOLS EXAMSPHP FormsSHARE THIS PAGEExamplePHP AdvancedPHP DatabaseComments in PHPWEB RESOURCESPHP XMLExamplePHP and AJAXPHP ExamplesPHP ReferencePHP Case SensitivityExampleExampleTop 10 TutorialsTop 10 ReferencesTop 10 ExamplesWeb CertificatesColor Picker