0

can someone tell me what's wrong with my code?My instructions say that i dont need to add any html elements to this document since it wont display in the web browser but i dont know what to do. Here's what i have:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xtml1-strict.dtd">
<html xmlns= "http://www.w3.org/1999/xhtml">

<html>
<?php

if (file_exists("messages.txt")	
	&& filesize("messages.txt") != 0) {

	$MessageArray = file("messages.txt");
	array_shift($MessageArray);
	$NewMessages = implode($MessageArray);
	$MessageStore = fopen("messages.txt", "w");
	fwrite($MessageStore, "$NewMessages");
	fclose($MessageStore);
}
header("location:ViewDiscussion.php");
?>

</html>
2
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by somedude3488
0

before i look through it, let us know if there are errors and such. Or maybe try telling us what it is that you are trying to do.

0

the errors are as follows coming from wdg html validator:

[TEX]

Errors and Warnings
Line 5, character 6: 
<html>
     ^Error: element html not allowed here; check which elements this element may be contained within

Line 21, character 7: 
</html>
      ^Error: missing a required sub-element of html

Line 21, character 9: 
</html>
        ^Error: html not finished but document ended

Line 21, character 9: 
</html>
        ^Error: end tag for html omitted; end tags are required in XML for non-empty elements; empty elements require an end tag or the start tag must end with />

Line 3, character 1: 
<html xmlns= "http://www.w3.org/1999/xhtml">
^start tag was here

Input
 1   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 2   "http://www.w3.org/TR/xhtml1/DTD/xtml1-strict.dtd">
 3   <html xmlns= "http://www.w3.org/1999/xhtml">
 4   
 5   <html>
 6   <?php
 7   
 8   if (file_exists("messages.txt")	
 9   	&& filesize("messages.txt") != 0) {
10   
11   	$MessageArray = file("messages.txt");
12   	array_shift($MessageArray);
13   	$NewMessages = implode($MessageArray);
14   	$MessageStore = fopen("messages.txt", "w");
15   	fwrite($MessageStore, "$NewMessages");
16   	fclose($MessageStore);
17   }
18   header("location:ViewDiscussion.php");
19   ?>
20   
21   </html>


[/TEX]
0

From an xhtml perspective:

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

has an extra space.

you have two <html> tags. you didn't define any <head> or <body> sections.

since you don't need this to be view in a web browser, get rid of all the html.

In the PHP portion:

try this:

<?php

$file = 'messages.txt';
if ( file_exists( $file ) && filesize( $file ) !== 0 ) {
	$messageArray = file( $file );
	array_shift( $messageArray );
	$messageStr = implode( "\n",$messageArray );
	$fh = @fopen( $file,'w' ) or die( 'Unable to open file' );
	@fwrite( $fh,$messageStr ) or die( 'Unable to write to file' );
	@fclose( $fh );
}
header( 'Location: ViewDiscussion.php' );
exit;

?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.