Thank you
echo and "<!--"... Help Please
Moderator: General Moderators
echo and "<!--"... Help Please
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

Thank you
Re: echo and "<!--"... Help Please
I also tried removing the comments. That did solved part of the issue, but when I got to 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 
Code: Select all
echo "<SCRIPT LANGUAGE='JavaScript'>";Re: echo and "<!--"... Help Please
It doesn't sound like your page is being parsed as php, so it's being displayed as html.
Re: echo and "<!--"... Help Please
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. 
- JAB Creations
- DevNet Resident
- Posts: 2341
- Joined: Thu Jan 13, 2005 6:44 pm
- Location: Sarasota Florida
- Contact:
Re: echo and "<!--"... Help Please
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...
...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. 
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>Re: echo and "<!--"... Help Please
There is if he's using HTML (as opposed to XHTML)JAB Creations wrote:1.) There is no "language" attribute in the script element.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.