[nycphp-talk] strpos with space
Hans Zaunere
lists at zaunere.com
Mon Jul 25 15:28:16 EDT 2005
Here are some old functions I've used to do similar things. I can't guarantee how well they work, but they should give you some ideas at least.
http://www.pcomd.net/word_bevel
http://www.pcomd.net/str_bevel
---
Hans Zaunere
President, Founder
New York PHP
http://www.nyphp.org <http://www.nyphp.org/>
AMP Technology
Supporting Apache, MySQL and PHP
_____
From: talk-bounces at lists.nyphp.org [mailto:talk-bounces at lists.nyphp.org] On Behalf Of Brian O'Connor
Sent: Monday, July 25, 2005 2:42 PM
To: talk at lists.nyphp.org
Subject: [nycphp-talk] strpos with space
I'm trying to create a function that displays the first 250 words of a text, and then puts " ... [ full text ] " (as a link). I did my research and I found the functions that I thought would work, however when I try to findt he 250th space (to determine where the 250th word would be) it doesn't seem to work, and the function only displays 250 characters.
Here is the function, maybe I am misunderstanding something:
function createTextPreview($text, $words = 250)
{
if(str_word_count($text) < $words) {
return $text;
} else {
return substr($text, 0, strpos($text, ' ', $words)) . ' ... [ <a href="link">full text</a> ]' . str_word_count($text);
}
}
Thanks in advance.
--
Brian O'Connor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20050725/b1c7a459/attachment.html>
More information about the talk
mailing list