Jump to content

Recommended Posts

Do you want to preform rtrim on characters on the right of the sentence or do you want to completely remove them?

 

It would be better to replace those $a(int) number of characters at the end with "...Read More"

 

or

 

worst case remove them.

Then you should go with substr() as Thorpe said.

 

ex

echo substr($sentence, 0, $a) . ' Read more...';

 

The problem with that is it will cut in the middle of words. Alternatively to get around this you can use this:

 

echo current(explode("\n", wordwrap($sentence, $a))) . ' Read more...';

 

wordwrap()

I can't speak for your specific case, but it seems more logical that you limit the amount of characters starting from the left. If you have strings that vary in length then you'll have different results. Wouldn't you want to have the strings with the 'Read more..' be the same length all the time? At least that's normally how it is.

I can't speak for your specific case, but it seems more logical that you limit the amount of characters starting from the left....

 

I know what you are saying, so I reversed my logic

 

//say 100 is total length
$a= //some int length
$b= 100 - $a

$result = current(explode("\n", wordwrap($sentence, $b))) . ' Read more...';

//Now I have $sentence[] as array...how do I do now...

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.