Jump to content

Recommended Posts

Could you be a little more descriptive?

 

How would you like to do this?  Cut off the end of the paragraph after a certain amount of words?

 

You could just explode the paragraph and only keep the first x amount of words...  but again, need more detail.

Thanks for the help, however im finding it hard to use substr.

 

Could some please post me the code, so that I can turn:

 

"With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post."

 

Into: "With Quick-Reply you can write"

 

There the code limits the paragraph to the first 5 words.

 

Thanks all.

* Not tested * - This SHOULD echo the first 4 words of the string.

 

$string = "With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post."

$short = "";
$pieces = explode(" ", $string);
for($i = 0; $i $short .= $pieces[$i] . " ";

echo $short;

This is assuming you want it to be cut into 10 words, roughly 50 characters:

 

<?php
$text = "With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.";

if (strlen($text) > 50) {
    $chopped = substr($text, 0, 50);
    echo $chopped . "...";
}else {
    echo $text;
}
?>

 

Simple as that.

 

Should do it.

 

 

EDIT:

This is an example using substr

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.