Intro to PHP: 01 “the echo”

March 9, 2010 by: Anthony Damasco

If your just getting into PHP you first need to know how it works. PHP actually creates HTML on the server side before the user loads the page. PHP is in charge of checking for arguments, getting data from databases and sending emails. PHP is also capable of much more if modules are installed on the server.

Getting your feet wet:

What you need to know:

  • HTML
  • FTP
  • An understanding of how web servers work.

PHP lets us do things that HTML does not. Let’s go through some basics.

<?php

echo “some stuff!”;

?>

To tell the webserver that you are using PHP you need to start with a <?php. You follow it with your code, then close it with ?>. Using echo tells PHP that we want to spit something into the HTML. You can echo anything. Javascripts, style sheets, anchor tags, and anything else that is valid in HTML.

what makes this important is the arguments that you use in PHP.

<?php

if ($this_variable==”HAPPY”) {

echo ‘<link rel=”stylesheet” type=”text/css” href=”css/SUPER_HAPPY_STYLE.css”>’;

}

else {

echo ‘<link rel=”stylesheet” type=”text/css” href=”css/SUPER_SADFACE_STYLE.css”>’;

}

?>

What the argument above is doing is checking a variable, and if it’s set to “Happy” then it will tell the page to use the happy style sheet, if its not, set it to the sad style sheet. This little snip of code could be used to let your visitors change the websites theme. I’ll cover variables next time!

-AD

More on Echo

Print vs Echo


Comments

4 Responses to “Intro to PHP: 01 “the echo””
  1. Hey, got to yahoo to your website and it looked strange but after refresh all displayed normal. Just thought id let you know and keep up the good work

  2. Phen375 says:

    It’s very hard to find stuff you are needing for these days unlike this page, thankyou

  3. Phen375 says:

    in what way do you think you can expand on this topic more?

  4. Phen375 says:

    It’s too impossible to find stuff you are looking for these days unlike this article, thx

Leave a Reply