Jump to content

I don't know what this is called, Naming help please?


gergy008

Recommended Posts

Hi guys, What is it called when you have a long paragraph shoretend, With php of course, To make it like haljh;lajbsdg...

 

For example, I have this paragraph:

 

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus placerat consequat enim, pretium viverra massa cursus nec. Sed in pharetra magna. Aliquam egestas vehicula mi, sed pellentesque ligula suscipit a. Donec lectus velit, luctus sed lobortis vitae, sollicitudin in sem. Ut facilisis, velit in accumsan porttitor, libero neque molestie leo, ac vulputate eros libero eget mauris. Ut nec justo augue.

 

How to I make it so PHP detects if it is too long and trims it down like:

 

Lorem ipsum dolor sit amet, consectetur adipiscing elit...

 

If I can find what this is called then I can google it to find it and use it on my site.

 

Thanks in advance!

I believe the word 'truncate' was in my previous response, yes, yes, I see it there!

 

My bad it was, And I found some code, I was looking for something like this:

 

    <?php
    function Truncate($string, $length, $stopanywhere=false) {
        //truncates a string to a certain char length, stopping on a word if not specified otherwise.
        if (strlen($string) > $length) {
            //limit hit!
            $string = substr($string,0,($length -3));
            if ($stopanywhere) {
                //stop anywhere
                $string .= '...';
            } else{
                //stop on a word.
                $string = substr($string,0,strrpos($string,' ')).'...';
            }
        }
        return $string;
    }
    ?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.