duanquanzhi5560 2012-10-17 12:47
浏览 96
已采纳

Stray html标签 - 发布Netbeans警告

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.

  • 写回答

3条回答 默认 最新

  • dongshimao7115 2012-10-17 13:17
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退