dongting7352 2013-12-21 01:11
浏览 40
已采纳

Wordpress - HTML文档不从第一行开始

I've been struggling with this problem for a long time now, but I cannot really find the solution. The problem is that < !DOCTYPE html etc... does not start at the first line, but leaves four blank lines before it starts.

All my files (header.php, index.php etc) have no line breaks before they start.

Anyone with any similar problems/experiences out there? It would have been of huge help!

See here for reference: view-source:http://2famous.tv/

Thank you

  • 写回答

1条回答 默认 最新

  • dongmacheng3222 2013-12-21 01:15
    关注

    This is most often not caused by leading but by trailing whitespace. Lots of old PHP code still closes down code at the end, which then all too often has a stray newline:

    <?php
    
      // Lot of source code
    
    ?>   <----- and a newline here which is the culprit!
    

    To avoid this issue, never close files with ?> - PHP doesn't need it and will just stop parsing at EOF, thus implicitly avoid this 'garbage' in the output.

    As for finding the files causing it - good luck, I'd start with combing any custom extensions for this and just removing all ?> markers that you can find.

    As an alternative, you can probably 'fix' it by adding a single ob_start() call to your index.php, and then in the template containing the doctype executing ob_end_clean() - this puts all intermediate output in the output buffers, and then trashes it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 制裁名单20240508芯片厂商
  • ¥20 易康econgnition精度验证
  • ¥15 线程问题判断多次进入
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接