dongxiusuo9881 2017-10-06 13:29
浏览 92

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.

  • 写回答

1条回答 默认 最新

  • dongzhe3171 2017-10-10 17:34
    关注

    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!

    评论

报告相同问题?

悬赏问题

  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容