SQL PHP HTML ASP JavaScript articles and free scripts to download
 

echo command & escape character in PHP

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 printf or echo command.



You have seen how we have used echo command to post our first string Hello World in our first lesion of PHP guide. Here it is again

<?
echo "Hello World";
?>

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.

<?
$date= date("m/d/y");
echo "Today is $date";
?>


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.

<?
$date= date("m/d/y");
echo "Today is $date, this value was stored inside variable \$date";
?>
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.
<?= $value ?>


We can also use escape character ( \ ) to print double quotes to the screen by using echo command. Here is an example.
<?
echo "John said \"He is learning PHP \" by reading ";
?>

Discuss this tutorial at forum


Further readings
Introduction to PHP: How scripting languages work
PHP beginners guide
echo command & escape character for string outputs
Adding delay to the script execution time by using sleep function
Printing Numbers 1 to 50 to screen
PHP Info: Details on PHP script settings & installation at server end
PHP Version : What is the version of PHP running at the server
Installing PHP on windows server and IIS
Installing PHP5 on windows server and IIS

 

Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.

Scripts
PHP
JavaScript
PHP Tutorials
Basics
PHP Sections
PHP Introduction
Loops & structure
Array
Date & Time
Functions
Form Handling
File Handling
Math Functions
String Functions
GD Functions
Comment Posting
Content Management
PHP & Ajax
Popular Tutorials
Drop down list
File Upload
Signup script
Member Login
Line Graph
PHP MySQL Paging
PHP Calendar
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.