Re: the last word of a string??
| From: | Mukul Sabharwal | Date: | Sun, 12 Aug 2001 06:21:37 +0000 |
| Subject: | Re: the last word of a string?? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-62294@lists.php.net to get a copy of this message | ||
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)];
--- "zerosumzero@yahoo.com" <zerosumzero@yahoo.com>
wrote:
> 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
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail:
> php-general-unsubscribe@lists.php.net
> For additional commands, e-mail:
> php-general-help@lists.php.net
> To contact the list administrators, e-mail:
> php-list-admin@lists.php.net
>
=====
*********************************
http://www.geocities.com/mimodit
*********************************
__________________________________________________
Do You Yahoo!?
Send instant messages & get email alerts with Yahoo! Messenger.
http://im.yahoo.com/