·  PHP – Syntax – Display


- Info:

  - This tutorial shows how to display data with PHP using echo() and print().

  - Additionaly you could also use printf() and sprintf() which give you options to format output.

    printf() otputs data to a browser while sprintf() assigns output to a string.


- Example:

  - Create PHP Console Application Test.php.





      //SINGLE LINE.---------------------------------------------------------------------------

      echo("Hello World.\n");       //Display to Console or Web Page

      echo "Hello World.\n";        //Same as above.

      echo "Hello"," World.", "\n"; //If you ommit paranthesis you can use multiple arguments.


      print("Hello World.\n");      //Display to Console or Web Page.

      print "Hello World.\n";       //Same as above.


      //MULTI LINE.---------------------------------------------------------------------------


    World.\n");                     //Works with and without paranthesis. 

      print "Hello

    World.\n";                      //Works with and without paranthesis. 


      //PRINT VARIABLE VALUE.-----------------------------------------------------------------

      $text = "John";

      echo("Hello $text.\n"); //Hello John  Variable is replaced     with value if placed inside "".

      echo('Hello $text.'  ); //Hello $text Variable is NOT replaced with value if placed inside ''.