You are here: Re: [PHP] Newbie Question: breaking a substr() string on a space SOLVED « PHP « IT news, forums, messages
Re: [PHP] Newbie Question: breaking a substr() string on a space SOLVED

Posted by Jackson Linux on 10/03/29 11:10

Hi, everyone,

Thanks for the great suggestions! I've looked at all and found that the
one here:

http://www.php.net/explode

that Jay recommended was the easiest for me to wrap my brain around. I
wll tinker with the other ones as well - it's all really interesting.

The function was:

function wordlimit($string, $length = 50, $ellipsis = "...")
{
$paragraph = explode(" ", $string);

if($length < count($paragraph))
{
for($i = 0; $i < $length; $i++)
{
if($i < $length - 1)
$output .= $paragraph[$i] . " ";
else
$output .= $paragraph[$i] . $ellipsis;
}

return $output;
}

return $string;
}

And boy does it work easily!!!

Thanks again all who replied.
Jack






On 11 Mar 2005, at 12:36, Richard Lynch wrote:

>
>> Hi, everyone,
>>
>> I'm 'teasers' of the first, say 200 to 250 characters of some
>> articles.
>> This works great:
>>
>> $content = strip_tags($article['content']);
>> $striptease = substr($content, 0, 275);
>>
>> but cuts off words right in the midd ...
>>
>> I'd like to find a way to take $content, look at the first 250
>> characters, then count backwards to the last space and chop it there.
>>
>> Does anyone have an ideas/scripts for this?
>
> $pos = strpos($content, ' ');
> $pos = $pos ? $pos : strlen($content);
> $teaser = substr($content, 0, $pos);
>
> --
> Like Music?
> http://l-i-e.com/artists.htm
>
>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация