Switch to full style
:read: Start PHP with us. Includes topics to help you in php
Post a reply

PHP echo command

Fri Sep 05, 2008 10:20 pm

As we saw in previews examples echo command is used for displaying the strings .you will use echo command many times in your web application .

Example of using echo command

Code:
<?
   
echo "<b>My name is tom</b>";
?>


or using a variable
Code:
<?
   $mystring
="My name is tom";
   echo
"<b> $mystring </b>";
?>


the output of both codes is :
My name is tom


Dealing with Quotes!

Guidelines :
* Don't use quotes inside your string
* Escape your quotes that are within the string with a backslash. To escape a quote just place a backslash directly before the quotation mark, i.e. \"
* Use single quotes (apostrophes) for quotes inside your string.

Here codes example :
Code:
<?php
// This won't work because of the quotes around myh5!
echo "<h5 class="myh5">I am 22 years old !</h5>"; 

// Now  work because we escaped the quotes!
echo "<h5 class=\"myh5\">I am 22 years old !</h5>"; 

// work , because we used an apostrophe '
echo "<h5 class='myh5'>I am 22 years old</h5>"; 
?>


Join variables and strings

you can join variables and text string using dot (.) .By this way you will save large number of echo command statements .

example

Code:
<?php
  $mystring ="<br/>Hi . my name is : ";
  echo $mystring." tom";
  echo $mystring." john";
?>


The output of this code is :
Code:
Hi . my name is :  tom
Hi . my name is :  john




Post a reply
  Related Posts  to : PHP echo command
 echo command to output HTML     -  
 Difference between PHP echo() and PHP print()?     -  
 echo client using Sockets     -  
 Echo multiline string     -  
 BETWEEN SQL COMMAND     -  
 Calling the man Command     -  
 SQL LOCATE command     -  
 SQL LIKE query Command     -  
 SQL ALTER Command     -  
 SQL GROUP BY Command     -  

Topic Tags

PHP Basics