PDA

View Full Version : Subtract part of BBCode using vB_BbCodeParser


zero477
11-08-2016, 04:23 PM
Hello to all,

I want to print part of a post using (like the first 100 words) the vB_BbCodeParser. If I use PHP sometimes I cut thre string in the middle of somewhere where I should not and I cannot display the html correctly.

For example:



$bbcode_parser =& new vB_BbCodeParser(vb::$vbulletin, fetch_tag_list(), true);
$text= '
<div class="review-text">
&quot;'.substr($bbcode_parser->parse($opiniones["pagetext"]), 0, 400).'...<a href="threads/'.$opiniones["threadid"].'-'.urlencode($opiniones["thread_title"]).'?p='.$opiniones["postid"].'#post'.$opiniones["postid"].'">ver m?s</a>...&quot;

</div>

echo $text;





Here, the link does not work because I cut the code incorrectly.

<span style="font-fam...<a href="thr


Any ideas?

noypiscripter
11-09-2016, 11:49 PM
Is this for vB5? Looks likes not.

Anyway, why not let the browser (via CSS) truncate the text and add ellipsis (...) depending on how wide the container of the text is?

$bbcode_parser =& new vB_BbCodeParser(vb::$vbulletin, fetch_tag_list(), true);
$text= '
<div class="review-text">
&quot;<span class="pagetext h-inline-block ellipsis">' . $opiniones["pagetext"] . '</span><a href="threads/'.$opiniones["threadid"].'-'.urlencode($opiniones["thread_title"]).'?p='.$opiniones["postid"].'#post'.$opiniones["postid"].'">ver m?s</a>...&quot;
</div>
';
echo $text;
Then add this in additional css:
.review-text .pagetext { width: 90%; }
vB5 has helper css classes ellipsis and h-inline-block to easily make an element behave like a text with ellipsis.

zero477
11-11-2016, 03:44 PM
Hello noypiscripter and thank you for your answer.

You are right, I am using vB 4 i posted in the wrong forum (Im sorry, hope that the moderators move this thread to the correct place).

Ill check if your solution works.

MarkFL
11-11-2016, 04:16 PM
...You are right, I am using vB 4 i posted in the wrong forum (Im sorry, hope that the moderators move this thread to the correct place)...

I've moved the thread, and in the future if you discover you have posted in the wrong forum, please feel free to use our post reporting feature to bring it to the attention of the moderating staff and request that the thread be moved. This will increase the odds that it will be moved. :)

noypiscripter
11-12-2016, 12:46 AM
Hello noypiscripter and thank you for your answer.

You are right, I am using vB 4 i posted in the wrong forum (Im sorry, hope that the moderators move this thread to the correct place).

Ill check if your solution works.

In that case, remove the h-inline-block and ellipsis css classes in the span tag and then replace this css in additional css:

.review-text .pagetext { width: 90%; }

with:

.review-text .pagetext {
display: inline-block;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
width: 90%;
}