Page 1 of 1
echo and "<!--"... Help Please
Posted: Sat Feb 21, 2009 10:09 am
by zunebuggy
I have a small PHP script that works great by itself. I have a website that has some javascript, HTML and comments. I converted the html, javascript and comments to echo commands (I've also tried print) but noticed that PHP does not like echo "<!-- where my comments are. As a matter of fact, when it encounters one it turns the rest of my echo statements into comments. When the PHP echos the lines, I would like the <!-- to show up in the final HTML source. There must be an escape character I can put before the <!-- to keep this from happening. Please help.
Thank you

Re: echo and "<!--"... Help Please
Posted: Sat Feb 21, 2009 10:19 am
by zunebuggy
I also tried removing the comments. That did solved part of the issue, but when I got to
Code: Select all
echo "<SCRIPT LANGUAGE='JavaScript'>";
it handles everything after that strangely. My graphics are now showing up on the page but I am seeing "echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; ...... written in plain text all over my page

Re: echo and "<!--"... Help Please
Posted: Sun Feb 22, 2009 2:08 am
by semlar
It doesn't sound like your page is being parsed as php, so it's being displayed as html.
Re: echo and "<!--"... Help Please
Posted: Sun Feb 22, 2009 7:44 am
by zunebuggy
I got it. I had my <? in the wrong place and did not notice it until I took a brek and came break with a fresh look at it.

Re: echo and "<!--"... Help Please
Posted: Sun Feb 22, 2009 7:52 am
by JAB Creations
1.) There is no "language" attribute in the script element.
2.) Do not use HTML comments to escape JavaScript data, this is a widely common perception.
Here is an example of correctly coded template page...
Code: Select all
<?php
header("Content-type: application/xhtml+xml");
echo '<?xml version="1.0" encoding="UTF-8"?>'."\n";?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Example</title>
<meta name="description" content="" />
<meta name="keywords" content="" />
<meta name="language" content="" />
<meta name="robots" content="" />
<script type="text/javascript">
//<![CDATA[
function change(id, newClass) {var identity=document.getElementById(id); identity.className=newClass;}
function example(event)
{
if (event < '3') {change('example_id','example_css_over');}
else if (event > '3') {change('example_id','example_css_out');}
}
//]]>
</script>
<style type="text/css">
div.example_css_over {background-color: #000; color: #fff;}
div.example_css_out {background-color: #fff; color: #000;}
</style>
</head>
<body>
<h1>Example</h1>
<div id="example_id"><p onmouseover="example('2');" onmouseout="example('4');">Example template</p></div>
</body>
</html>
...if you remove the code on 13 and 21 the page will break. You can not test this in Internet Explorer as it does not support XHTML, I recommend testing this with Firefox as if you remove those two lines and execute the page you'll see
exactly what I'm talking about. Have fun.

Re: echo and "<!--"... Help Please
Posted: Mon Feb 23, 2009 10:41 am
by pickle
JAB Creations wrote:1.) There is no "language" attribute in the script element.
There is if he's using HTML (as opposed to XHTML)