Dimitris Papageorgiou
Dimitris Papageorgiou

Reputation: 447

Stray html tag- Netbeans warning issued

I have written a function where code related to the headers of a site are included. This is the function:

First of all, is there any problem with a coding such as the above-anything at all? Secondly, Netbeans issues a warning in the html tag: Stray start html tag here. I suppose this happens because the html tag is enclosed in a function and this functions does not contain the end tag-I assume.

function output_headers()
{?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Appointmetns24x7</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet"  href="css/admingeneral.css"/>
script  type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js" ></script>
</head>
<body> <?php
}

If there is nothing wrong with this coding scheme then I will just ignore netbeans warning and continue.

Upvotes: 0

Views: 2662

Answers (3)

Dimitris Papageorgiou
Dimitris Papageorgiou

Reputation: 447

It seems that if you enclose root type html(html tag) elements inside a function and then close them in a place on the script outside the function the beginning tag was set-then this interpreted as error in Netbeans.

Someone can just choose to ignore it, else he should avoid coding this way, putting html header info in a function.

Upvotes: 1

SDC
SDC

Reputation: 14222

The actual error message is due to the <body> tag not being closed. Netbeans is picking this up and warning you that the HTML may be invalid... because it is invalid. Netbeans has no way of knowing just by looking at this function that it shouldn't be a complete HTML document.

If you must do things this way, you should avoid splitting individual HTML tags between different code blocks. Best practice would be to make sure that any function that outputs an HTML tag also outputs the corresponding closing tag.

However the way you're doing things is not ideal in any case.

You've split your template into a 'header' and (presumably) a 'footer' function. This sort of technique was quite common years ago, but these days it's not considered particularly good practice.

A better technique would be to have a separate template file, which contains all your HTML -- ie the header and the footer, with placeholders where you want the dynamic content to go. You then build the dynamic content bits as strings, and feed them into the template.

In its simplest form, this just means that the template is a plain HTML file with PHP blocks, for placeholders like <?php echo $mainBodyCode; ?> in the appropriate places. You then just need to make sure the placeholder variables are populated, and include it when you want to output the page.

Hope that helps.

Upvotes: 3

Ryan B
Ryan B

Reputation: 3392

I would sat the stray tag is the

xmlns="http://www.w3.org/1999/xhtml"

because you called <!DOCTYPE html> which isn't xhtml, so calling the xml namespace is invalid.

Upvotes: 1

Related Questions