View Full Version : PHP Tag Style
I'm just learning PHP via a new book: PHP and MySQL (Luke Welling & Laura Thomsen). They use a "short tag" style. When I put the following into the page code:
<? echo "<p>Order processed."; ?>
which is how they show it, the resulting page shows this:
Order processed."; ?>
Why is it printing the stuff after "Order processed."?
I also can't seem to get comment lines using either // or # to not print.
Any help greatly appreciated.
Mark-
Thanks Marty,
My problem was even simpler. I'm embarassed to say I just figured out I have to end the html file with ".php" instead of the usual ".html".
Duh!
Mark-
Something is still wrong. Take a look at:
http://www.etomicpower.com/php/bob.php
It's printing the comment line and if you view the source it's showing the php code, which I don't think it's supposed to.
Is PHP automatically activated on resellers accounts or do I need to activate it somehow?
Mark-
Annette
05-11-2001, 07:02 PM
There isn't really anything to enable with regard to PHP - the server is simply configured to parse certain files using PHP.
That said, we'd need to see the code of bob.php, instead of the output from it.
Weird science. I swear to God that last night before I posted that last message, if you did a "view source" from the generated page, it was showing the php code. So this morning I read your posts and think, "didn't they read my post about it showing the code"? So I go to the page again and low and behold, it's not showing the code in the generated page. The computer has always been a great tool for helping me look foolish.
Anyway, that aspect seems to be working but I still can't seem to get rid of the comment lines. I've tried: # comment, // comment, and /* comment */
They're all printing.
Mark-
Tuppence
05-15-2001, 07:13 PM
Interesting.
The standard comment problem with /* .... */ is to accidentally build /* ... /* .... */ .... */ = however that will give you a PHP parse error, so that is not your problem.
This PHP snippet
<?php echo "Some text to be output " ?>
produces
Some text to be output
While this snippet
<?php echo"Some text to be output /* with a comment */ to be missed out" ?>
produces
Some text to be output /* with a comment */ to be missed out
And, for completeness, this snippet
/*
<?php echo"Some text to be output /* with a comment */ to be missed out" ?>
*/
produces
/* Some text to be output /* with a comment */ to be missed out*/
The conclusion?
You are constructing a PHP snippet where the commented text is not under the control of PHP.
There are two cases.
The second snippet shows the comment inside the scope of the echo - PHP is busy ignoring everything till it get to the next speech mark so the comment gets printed.
The third snippet shows the second case contained inside comment markers which are output by the HTML because they are outside the PHP tags.
Not being able to see your PHP I do not know what you are doing, but I wonder if it might be one of these two possibilities.
HTH
And, by the way, apart from the header to a chunk of code where I use a block of text describing what is going to happen, I use the // comments on the ends of lines on the twin grounds of clarity for reading the text and lesser likelihood of tangles.
TD
Here is the code for:
http://www.etomicpower.com/php/bob.php
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<h2>Bob's Auto Parts </h2>
<? echo "<p>Order processed.";
echo date("H:i, jS F");
?>
/* what's this */
</body>
</html>
It is still printing the comment line and I also tried // what's this //. That prints as well.
Mark-
Annette
05-15-2001, 09:42 PM
Your /* what's this */ is not actually part of the php code, but the HTML code. You can put in a comment for HTML instead:
<!-- what's this -->
vBulletin® v3.6.8, Copyright ©2000-2008, Jelsoft Enterprises Ltd.