• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
Techgoeasy

Techgoeasy

Learn Oracle, PHP, HTML,CSS,Perl,UNIX shell scripts

  • Home
  • Oracle
    • Oracle database
    • Oracle Ebusiness Suite
    • Oracle weblogic
    • Oracle Performance Tuning
    • Oracle Hyperion
    • Oracle Cloud Tutorials
  • SQL
  • interview questions
  • Linux
  • PHP and HTML
  • Downloads
  • General
Home » Web development » PHP » PHP echo construct

PHP echo construct

June 9, 2014 by techgoeasy Leave a Comment

Today I had learned about echo in PHP , it is not a function , it is a language construct. By language construct I mean that meaning that it is an integral part of PHP itself. It allows us to output data on the users web browser. You can output values stored in a variable using echo or you can also output string data using echo. We can use both single quotation mark ‘ ‘ or double quotation mark ” “ while using echo. Double quotation mark are used when you want to output value of some variable to the browser in a program and your line must terminate with the semi colon ;

<?php
echo "!I am echo construct!";
?>

Now this would output !I am echo construct! to the web browser. Now the semi-colan (;) at the end of the echo command is used to mention the end of the echo construct. Without this semi-colon PHP would report an error.
So previous example shows the use of echo with double quotation marks. As stated earlier we can also use it with single quotation marks as shown below

<?php
echo '!I am echo construct!';
?>

Now this would also output !I am echo construct! to the web browser.

In PHP we can also use echo to do arithmetic as can be seen in following example

Here line 2 is

<?php
echo 20+20;
echo '20+20';
?>

echo 20+20;

This would output 40. This means echo command can be used for doing arithmetic and here note that quotation marks have not been used. You can also subtract , do division and multiplication using this echo construct.

Here line 3 is

echo ’20+20′;

This would literally output 20+20. This happens because quotation marks were used, this was processed as a string instead of a mathematical operation. And same thing would happen if we use double quotation marks instead of single quotation marks.

Hope you like post on echo in PHP

Also Reads
How to run php file in windows : This post talks about how we can php file on the the window and do the testing before moving to the web server
uses of PHP : This has detailed description why PHP is so much used through out the world.
first php program : This is good starting point for anybody starting with PHP and talk in good detail about how to write your PHP program and execute it
Define constant in PHP
PHP String Functions
PHP Array functions
https://en.wikipedia.org/wiki/PHP

Filed Under: PHP, Web development Tagged With: php echo construct

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar



Subscribe to our mailing list

Enter your email address to subscribe to this blog and receive notifications of new posts by email

Recent Posts

  • How to generate sql monitor report in Oracle
  • How to find the long running (longops session) in Oracle
  • How to find concurrent request id from Sid or spid
  • how to check recycle bin in oracle: Purge, enable/disable
  • how to check fra size in oracle: Location, usage, change size

Copyright © 2023 : TechGoEasy

  • Hire me
  • Privacy Policy
  • Contact Us
  • New? Start Here
  • About Us