Kaolin Fire with GUD Issues 0 through 5

kaolin fire presents :: PHP 101 :: Is PHP Running?


How many fingers do you see?


Is PHP Running? How many fingers do you see?

We're going to make one simple php page, just to validate a few of our previous assumptions. This will be your first introduction to php in these lessons.

One, simple page, that validates

I know this is simple, really simple, but there are hurdles with it even still. This is how you make sure you've got most of the assumptions of the "assumptions" lesson taken care of.

Here's what I want you to put into orwell.php somewhere, for testing. If you see 2+2=5, you're a winner!

<?php echo "<"; ?>?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
<head><title>Orwellian Lesson</title></head>
<body>
<p>2 + 2 = <?php echo 5; echo "<!-- "; ?>4<?php echo " -->"; ?></p>
</body>
</html>

I know, that's a lot to bite off all at once. Consider these lessons a guidebook—you've got to get to the scenery yourself, and then I'll tell you about it some. This chunk of code above is actually likely to be the most help I out and out give you right to start. And the reason I put so much instead of just the info between the para tag is that I care. I want you to do things right. I want right to be both a habit and a mission. And while the way I do it isn't the _only_ right, I do try fairly hard.

The first thing in the file is that "<?php" tag. Why? We're not really doing any php right there but printing something that we could have just typed. The answer is that some installations of php allow you to use <? to open a php statement. If you have yours set that way, turn it off. It's sloppy, and doesn't cross installations very well. You always have to assume your code is going to be put in the worst possible place, that will almost, sort of, kind of still run—it if go through all the code and fix minor inconsistencies. It's better to have as many of those annoyances out of the way as possible.

So what's the "<?xml" thing? That's because I like XHTML, and XHTML is XML, which is a subset of SGML, yadda yadda. Just... well, if you want to know more, you know where to look for the information. DOCTYPE and all that as well.

Into the meat of the exercise, then, we see good old 2+2. If you've got everything set up properly, then php will print out a 5, then print out html comment marks around the 4. You'll see 2 + 2 = 5. If things aren't working right, well, you'll see a bit of a jumbled mess, but it's likely that in that jumbled mess, you'll see 2 + 2 = 4. HTML is an "expandable" language, and your browser wants to be as flexible as it can. If it doesn't recognize a tag, something starting with a <, even if it's a <?, it'll just ignore it. That includes all the text inside of it, up until the first closing >.

Which do you see? a or b?

Presuming a, check it out with the w3c validator!

It should be valid xhtml 1.1, unless you decided to start tinkering with the code already, or your server is munging things. Good luck. Mine validates. If yours doesn't validate, see if you can figure out the error(s) it gives you, and see if you can come up with a way around those errors. As ever, google is your friend!




I am soooo fake pre-loading this image so the navigation doesn't skip while loading the over state.  I know I could use the sliding doors technique to avoid this fate, but I am too lazy.