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!

Link to comment
Share on other sites

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;
    }
    ?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.