Saturday, December 8, 2012

PHP Echo Command - PHP Lesson 1

The PHP Echo command
By Stephon Unomon

We’re going to tell PHP to output something to the screen. Keep in mind that PHP can be used in conjunction with HTML, but we are not showing the code in this example, to keep it simple:

 

<?php echo “Creamy Bagels”; ?>

 

(I hate the “Hello World” sample that every other book in the world uses, so I’m using “Creamy Bagels” instead.)

 

       Let’s dissect the command example bit by bit, shall we? It helps to do this when you are looking at a LOT of PHP code...because, trust me, it can look like a jumbled blurry mess sometimes if you don’t take it piece by piece!
 

<?php - tells the server to process this as php code...

 

echo “Creamy Bagels” ; - tells the server to write what’s in the quotes to the screen, and that the semicolon is ending this particular command...

 

?> - tells the webserver, “OK, I’m done with PHP for now. Back to regular HTML”.

 

Pretty simple when you look at it that way, yes?

 

 

“OK, that’s cool..but what if I want to see quotes on my screen?”

 

 

This can be done by “escaping” the PHP code for what you want to show up in quotes. Let’s use the example from above...

 

<?php echo “Creamy Bagels”; ?>

If you wanted to see quotes around Creamy Bagels, you would use the following code instead:

 

<?php echo “\”Creamy Bagels\””; ?>

Using \” tells PHP that you want a quotation mark to appear. Remember this - it is important, and will be used in the later lessons.
 
 

3 comments:

  1. Awesome i have never read this language in this way it's very simple.. i didn't know before meaning of sign. like what is the logic or what these signs do with the server.. Great Job

    ReplyDelete
  2. Thanks, Im glad it helped. I seen your post and just wanted to respond because I love helping people learn PHP. If you ever have any questions just email them to me at koolphpsuite@gmail.com

    ReplyDelete