🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.comp.lang.php
Article #56

Re: How do I do this?

#56
From: Egbert Teeselink
Date: Thu, 24 May 2001 08:50
27 lines
2017 bytes
> <?php
> $lines = file(lines.txt);
> echo $lines[sizeof($lines)-1];
> ?>
>
> or
>
> <?php
> $lines = file(lines.txt);
> echo $lines[sizeof($lines)];
> ?>
>
> depending on whether your text file has a trailing cr/lf.

could be combined as

<?php
$lines = file("lines.txt"); //you forgot the quotes here :)
$sf = sizeof($lines);
echo (empty(trim($lines[$sf])) ? $lines[$sf - 1] : $lines[$sf]);
?>

making it not matter anymore whether the file has a cr/lf at the end or not.
(note, only having whitespace characters on the last line, which should be
echoed instead of ignored, will be heavily screwed up by this)

skrebbel.
Technical Details
Message-ID: <990694205.1479.0.pluto.d4ee1efb@news.demon.nl>
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.icl.net!dispose.news.demon.net!news.demon.nl!demon!teeselink.demon.nl!not-for-mail
References: <kZWO6.8315$FL1.909094@afrodite.telenet-ops.be> <9efogt04fd89qalgmhc6bao25f0guub95m@4ax.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10f92b,39486179625bfc13
X-Google-Attributes: gid10f92b,public
X-Google-Thread: f9981,39486179625bfc13
X-Google-Attributes: gidf9981,public
X-Google-Thread: 1156bd,39486179625bfc13
X-Google-Attributes: gid1156bd,public
X-Google-Thread: 1107bb,39486179625bfc13
X-Google-Attributes: gid1107bb,public
X-Google-ArrivalTime: 2001-05-24 01:51:10 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.icl.net!dispose.news.demon.net!news.demon.nl!demon!teeselink.demon.nl!not-for-mail
From: "Egbert Teeselink" <eggbird@bigfoot.com>
Newsgroups: alt.comp.lang.php,alt.php,cz.comp.lang.php,de.comp.lang.php
Subject: Re: How do I do this?
Date: Thu, 24 May 2001 10:50:35 +0200
Message-ID: <990694205.1479.0.pluto.d4ee1efb@news.demon.nl>
References: <kZWO6.8315$FL1.909094@afrodite.telenet-ops.be> <9efogt04fd89qalgmhc6bao25f0guub95m@4ax.com>
NNTP-Posting-Host: teeselink.demon.nl
X-NNTP-Posting-Host: teeselink.demon.nl:212.238.30.251
X-Trace: news.demon.nl 990694205 pluto:1479 NO-IDENT teeselink.demon.nl:212.238.30.251
X-Complaints-To: abuse@nl.demon.net
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.50.4522.1200
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200
Lines: 29