Re: the last word of a string??
| From: | zerosumzero@yahoo.com | Date: | Sat, 18 Aug 2001 14:09:30 +0000 |
| Subject: | Re: the last word of a string?? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-62305@lists.php.net to get a copy of this message | ||
on 8/12/01 2:21 AM, Mukul Sabharwal at mukulsabharwal@yahoo.com wrote:
> Hi,
>
> here :
>
> $arr = explode($lastline, " ");
>
> that puts lastline into arr which is an array and you
> can use the sizeof operator to get the nth (or the
> last) element.
>
> print $arr[sizeof($arr)];
hmmm I tried this... it seems not to recognise the space. The sizeof($arr)
is always 1.
Susan
---
So I opened a file like this:
$filename ="text.txt";
$fh = fopen($filename, "r");
then I get the last line of the file like this:
while (!feof ($fh)) {
$lastline = fgets($fh, 4096);
}
now I want the last word of $lastline ... how do I do this? I've been
trying all kinds of things but nothing seems to be what I need.
I would also like to be able to get the last X words of $lastline?
so if
$lastline = "I am a newbie"
I get: "am a newbie"
Help!
--
susan@futurebird.com
http://futurebird.diaryland.com