NYCPHP Meetup

NYPHP.org

[nycphp-talk] strpos with space

Brian O'Connor gatzby3jr at gmail.com
Mon Jul 25 15:15:24 EDT 2005


Same result, and I also tried replacing $words altogether with 250 just to 
test that, and still the same result. 

As a side note, the . str_word_count($text) is there for debugging purposes 
and I didn't get around to taking it out.

On 7/25/05, CED <Consult at covenantedesign.com> wrote:
> 
> Try NOT setting the value of $words in the paramater.
>  try 
> <?
>  $words = 250 ;
>  function creatText($text, $words)
>  { 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);
> } 
> }
>  ?>
>   
> ----- Original Message ----- 
> *From:* Brian O'Connor <gatzby3jr at gmail.com> 
> *To:* talk at lists.nyphp.org 
> *Sent:* Monday, July 25, 2005 2:41 PM
> *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 
> 
> ------------------------------
> 
> _______________________________________________
> New York PHP Talk Mailing List
> AMP Technology
> Supporting Apache, MySQL and PHP
> http://lists.nyphp.org/mailman/listinfo/talk
> http://www.nyphp.org
> 
> 
> _______________________________________________
> New York PHP Talk Mailing List
> AMP Technology
> Supporting Apache, MySQL and PHP
> http://lists.nyphp.org/mailman/listinfo/talk
> http://www.nyphp.org
> 
> 


-- 
Brian O'Connor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20050725/0fc6534f/attachment.html>


More information about the talk mailing list