Re: splitting text after 25 words
| From: | karthik | Date: | Sun, 08 Jul 2001 06:09:52 +0000 |
| Subject: | Re: splitting text after 25 words | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-61755@lists.php.net to get a copy of this message | ||
Hi,
Best way i guess would be traverse the whole string and check for space.
Have a counter var which keeps count of the space. At the 25th occurence do
something like this -
$text_a = substr($text, 1, $i);
i assume that $i is the increment var in the loop.
$text_b = substr($text, $i+1);
This should give u the strings in 2 vars.
Now u can add anything with $text_a."...Click here ".$text_b
Hope i was helpful,
Karthik.
----- Original Message -----
From: "Justin French" <justin@indent.com.au>
To: "php" <php-general@lists.php.net>
Sent: Wednesday, August 08, 2001 10:27 AM
Subject: [PHP] splitting text after 25 words
> Hi all,
>
> I'd like to split a text block at 25 words, as a teaser for the full
> article. Now I know how to split at a certain character, but i don't
> want a half word or anything, so I want (i guess) to hunt for the 25th
> occurence of " " (a space), and split $text into two new variables,
> $text_a and $text_b.
>
> Then I'll prolly want append something like "... click here to read
> more" on the end of $text_a.
>
> Seems easy enough, but I can't see anything in the manual about
> splitting on a numbered occurence of a string (but I could be looking
> in the wrong spot :)
>
> Running PHP4 BTW
>
>
>
> Thanks heaps in advance
> Justin French
>
> --
> 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
>
>