TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   Crop Content (http://www.talkphp.com/general/5220-crop-content.html)

CΛSTΞX 01-13-2010 06:37 PM

Crop Content
 
Hello, this snippet crops the content and puts "..." to the end. My question is, how can I get the rest of the content ?

PHP Code:

<?

$str 
"Yeah, but on my website, before I realized that converting quotes, etc, to entities was a bad idea, I already had a lot of stuff put into a database...Also, symbols like show up as question marks... and I don't really know how to fix that. In my four years of HTML experience, and two years of PHP experience, I've never been able to get character encoding to do what I want it to.";

$chars "150";

function 
shortText($str$chars)
{
if (
strlen($str) > $chars)
    {
    
$str substr($str0$chars);
    
$str $str "...";
    return 
$str;
    }
else
    {
return 
$str;
    }
}

echo 
shortText($str$chars);

?>


Parvus 01-13-2010 09:08 PM

Do you mean like this ?
PHP Code:

<?

$str 
"Yeah, but on my website, before I realized that converting quotes, etc, to entities was a bad idea, I already had a lot of stuff put into a database...Also, symbols like show up as question marks... and I don't really know how to fix that. In my four years of HTML experience, and two years of PHP experience, I've never been able to get character encoding to do what I want it to.";

$chars "150";

function 
shortText($str$chars)
{
if (
strlen($str) > $chars)
    {
    
$str substr($str0$chars);
    
$str $str "<a href='/link-to-full-article.html'>...</a>";
    return 
$str;
    }
else
    {
return 
$str;
    }
}

echo 
shortText($str$chars);

?>

So you can click on the 3 dots to go to the full page ?
or do you just mean echo($str); ?

CΛSTΞX 01-13-2010 09:58 PM

I just want to get the section which starts with "..." (script does this after 150 chars) and finishes at the end.

delayedinsanity 01-14-2010 07:38 PM

Well since the above code isn't worried about cropping at a space or punctuation, I won't worry either. :)

php Code:
$remainder = substr( $str, $chars );


All times are GMT. The time now is 12:27 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0