We’re going to tackle the basics to start with. Getting PHP to write things to the web browser, what variables are and how to use them... examples you can use in just about every web page you create.
Let’s start with the most basic one.
The PHP Echo command
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.
0 Comments
Leave a Reply. |
David Rentson
If this free PHP and MYSQL Tutorial is helpful for you... Great! Archives
October 2008
Categories
All
|