echo command & escape character in PHP

Output text with echo

echo is a language construct for sending one or more strings to the response. Concatenate values with the dot operator when that keeps the output clear.

<?php
$name = 'Alex';
echo 'Hello, ' . $name;
echo Printing or sending output to browser at client side is the main objective for which we will be developing our scripts in PHP. Finally after processing the code at server side we manage the output various ways and send them by using one echo command.

First PHP page for Hello world output and checking installation with phpinfo() and uses of comments


You have seen how we have used echo command to post our first string Hello World in our first lesson of PHP guide. Here it is again
<?Php<br>
echo &quot;Hello World&quot;;<br>
?>
To learn more on this let us try to print the value of a PHP variable. To start with let us print today's date by using one variable.

<?Php<br>
$date= date(&quot;m/d/y&quot;);<br>
echo &quot;Today is $date&quot;;<br>
?>
Some time we may require to print the name of the variable than printing the data. So here we will use escape character ( \ ) before the $ symbol to tell PHP that consider the next character as string and not as a variable.

<?Php<br>
$date= date(&quot;m/d/y&quot;);<br>
echo &quot;Today is $date, this value was stored inside variable \$date&quot;;<br>
?>

Using PHP within HTML codes.

Some time within a code block of HTML we want to display the data of a PHP variable. For this we need not use the PHP start command and then echo command, we can use short method like this to display the data stored in variable $value.
<?Php echo  $value; ?>
We can also use escape character ( \ ) to print double quotes to the screen by using echo command. Here is an example.
<?Php<br>
echo &quot;John said \"He is learning PHP \" by reading &quot;;<br>
?>
Output is here
John said "He is learning PHP " by reading 

print to output string Introduction to PHP Adding delay to script execution Guide to installation and How to write our first PHP Script



Subscribe to our YouTube Channel here



plus2net.com







Dan Land

27-02-2010

Your tutorial is helpful and most appreciated. I've learned a lot




PHP video Tutorials
✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer