开发者

Error found in xHTML output due to PHP's variables, $_SERVER and <ADDRESS>

I'm having this problem with validating a document that contains some basic PHP variables. Mainly I'm using html's h1, h2, and pre codes for formatting the text.

My problem is that when I validate the document, it comes out with an error.

The problem area is this part of the file:

<h2>Server Info</h2>

<pre>
<?php
echo $_SERVER;
print_r(var_dump($_SERVER));
?>
</pre>

I'm trying to figure out what's going whenever I try to validate it, I get an undefined elem开发者_Python百科ent error.

Here's a link to the validation page: http://goo.gl/napu EDIT: Link to the complete HTML source that's getting the error: http://pastebin.com/Kc6wh5s6

2ND EDIT: Used Pekka's suggestion and inserted the PHP snippet and now the page has been passed. Thanks!


The problem is that the $_SERVER dump contains code that looks like a XML element, namely <ADDRESS>. The validator is obliged to deal with that like with every other HTML element, and fails.

The solution would be to run a htmlentities() over the output to mask any included HTML or XML, e.g. like so:

$result = print_r($_SERVER, true);
echo htmlentities($result);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜