Jump to content

Recommended Posts

Hi,

i'm trying to figure out how can i do a link break something similar to joomla's text editor.

i creating a website that has a news & events section, in that i show the title and part of the text with a read more link.

to show part of the text i use this code:

$description = substr($row['description'], 0, 150)

it is a good method but most of the time the words are chopped in the middle.

 

in the backend i'm using a rich text editor called jQuery WYSIWYG http://code.google.com/p/jwysiwyg/ to add text.

 

how can can show part of the text without having words chopped of at the end?? or make the user choose where the part text should end?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/189564-creating-a-line-break/
Share on other sites

wordwrap doesn't help me since i still need to give it a number.

however, i've able to fix my issue by using the <hr> tag

 

the text editor i use creates this tag whenever i press on the horizontal rule:

<br><hr size="2" width="100%">

 

so i use the explode to get all the text before the <hr> tag which the users specified

$description = explode("<br><hr size=\"2\" width=\"100%\">", $row['description']);
echo $description[0];

 

now all i have to do is figure how to remove it from the full article page??

 

i'm thinking about searching for it using preg_match and replacing it with empty quotes

thanks tryingtolearn, str_word_count didn't help much but a user (charliefrancis at gmail dot com) posted this code at the same page

 

function word_limiter( $text, $limit = 30, $chars = '0123456789' ) {
    if( strlen( $text ) > $limit ) {
        $words = str_word_count( $text, 2, $chars );
        $words = array_reverse( $words, TRUE );
        foreach( $words as $length => $word ) {
            if( $length + strlen( $word ) >= $limit ) {
                array_shift( $words );
            } else {
                break;
            }
        }
        $words = array_reverse( $words );
        $text = implode( " ", $words ) . '…';
    }
    return $text;
}

 

It returns a string with a certain character limit, but still retaining whole words which is perfect for me

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.