-1

Ok so i will try to explain it as much better as I can. P.S sorry for my gram.. Ok so i have a cms forum system(phpbb) and I am making integration with the site. So when i write a topic in X forum it appears as a "News" in the index of the site. So perfect! But i have a problem! I want to cut the selected text if it's longer than 30 symbols. My code for now is Content: <?php $row['content']; ?> . What should I do so i can cut x symbols from it ? I guess it's something like jquery or javascript ? Maybe with tags and etc. Thanks for the help !

1 Answers1

0
var content = "This is your content and we are looking truncate to thirty chars";

if (content.length >= 30) {
    var shortText = jQuery.trim(content).substring(0, 30).split(" ").slice(0, -1).join(" ") + "...";
    alert(shortText);
}

You may want to see this post also How Can I Truncate A String In jQuery?

In place of the content you will need to print your content into the var then truncate the content var.

var content = <? echo $row['content']; ?>;

Then you will need to find the length of the var and do a check to see if it is greater than 30 chars...if it is then truncate it.

here is a fiddle Check Me Out

Community
  • 1
  • 1
Xanfar
  • 156
  • 5