简体   繁体   中英

Php include to skip the first 12 lines read

I am reading data from a htm page into a Wordpress post with <?php include("liveresults/140403F001.htm"); ?> <?php include("liveresults/140403F001.htm"); ?> it works perfectly. I however need to skip the first 12 lines of the html file and only start reading from line 13. Any ideas?

If the file only contains HTML and you don't want to execute it as PHP, then you should not be using include anyway. readfile() is much better suited for that.

However, since you want to ignore the first 12 lines, you should use an SplFileObject which allows you to seek by line:

$file = new SplFileObject("liveresults/140403F001.htm");
$file->seek(12);
$file->fpassthru();

Note that if your file comes from some sort of external input, you should escape it for HTML, to guard against XSS.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM