XHTML 1.0验证 - PHP代码行引发错误。 为什么? 怎么修?

I'm working on a school project in PHP and my web pages have to pass XHTML 1.0 Validation.

The following line of code throws errors.

<img src="<?php echo './img/'. dayOfWeek(). '.png'?>" alt="<?php echo dayOfWeek() ?>" />

Error Line 116, Column 18: Unescaped '<' not allowed in attributes values

<img src="<?php echo './img/'. dayOfWeek(). '.png'?>" alt="<?php echo d…

✉

Error Line 116, Column 18: attributes construct error

<img src="<?php echo './img/'. dayOfWeek(). '.png'?>" alt="<?php echo d…

✉

Error Line 116, Column 18: Couldn't find end of Start Tag img line 116

<img src="<?php echo './img/'. dayOfWeek(). '.png'?>" alt="<?php echo d…

Any suggestions as to why this is happening and how to fix will be much appreciated.

Error handling is important. Hopefully this code based on mature live platform will help you.

<?php
error_reporting(E_ALL);

//No errors if live, outputs errors if local testing.
ini_set('display_errors', substr($_SERVER['HTTP_HOST'],0,4)=='www.' ? 0 : 1);

//Use an include and put the error handling function there.
set_error_handler('error_handle');

function error_handle($errno,$errstr,$errfile,$errline)
{
 //Quick dump.
 //You should store all errors (HTTP, JavaScript, PHP and SQL) in logs.
 echo '<div><p>errno = '.$errno.'</p></div>';
 echo '<div><p>errstr = '.errstr.'</p></div>';
 echo '<div><p>errfile = '.$errfile.'</p></div>';
 echo '<div><p>errline = '.$errline.'</p></div>';
}
?>

Also ensure that your XHTML is XHTML by serving the correct mime header:

<?php
if (stristr($_SERVER['HTTP_ACCEPT'],'application/xhtml+xml'))
{
 $mime = 'application/xhtml+xml; charset=UTF-8';
}
else
{
 $mime = 'text/html; charset=UTF-8';//Not UTF-8 string for IE6 but no longer valid 2010+.
}

header('Content-Type: '.$mime);
?>

If you would like further insight in to XHTML5 (HTML5 using the XML parser) see my website in my profile; it's an entire web platform that uses this winning combination. Best of luck!