I need to limit the number of charachters in an entry. I’ve found numerous plugins for doing this but none of them close the paragraph, making my code fail validation.
Are there any plugins that will do this?
I have tried pi.char_limit, pi.tag_limit, pi.trunc_html, pi.word_limit and pi.word_limit_plus
Assistance with this would be greatly appreciated.
I use the excellent Word Limit Plus and have modified it slightly for the very reason you raised this post on.
I changed the following lines:-
if ($the_link != "") {
$str .= "<br><br>" . $the_link;
}
to
if ($the_link != "") {
$str .= "" . $the_link . "";
} else {
$str .= "";
}
My code amends do change the output if you provide a ‘the_link=’ parameter though, as I did not want 2 linebreaks, just the link on the same last line, e.g.
this is the text being trunc…Read on
Thanks for your replies
dvancouver - I am using a strict doctype yes.
baboonbrand - Yeah i have tried this, but then i realised if my paragraph ended naturally with the same amount of charachters set for the plugin parameter then i will have two </p> tags.
silenz - i was not aware of this, i’ll check it out thanks.
OK, I don’t have much time, but what about something like the attached amendment:-
I made a very crude php function to parse the string to see if a closing p exists, and if not then append one. However, i’m not a great php hardcore programmer, so I fully expect soemone to (a) correct me on where it’s wrong and (b) do the same but in one line!
I have changed this:-
if ($the_link != "") {
$str .= "" . $the_link . "";
} else {
$str .= "";
}
return trim($str);
}
// END
to this…
if ($the_link != "") {
$str .= "" . $the_link . $this->Close_Paragraph ($str);
} else {
$str .= $this->Close_Paragraph($str);
}
return trim($str);
}
// END
function Close_Paragraph($str)
{
$CP='';
$iPosOpen = strrpos($str,"");
if ($iPosOpen===false)
{
} else {
$iPosClose = (strrpos($str,"",$iPosOpen));
if ($iPosClose === false)
{
$CP = "";
} else {
}
}
return $CP;
}
Like I said, please feel free to do a better job you guys out there, I just want to make something work…:D And sorry if I break any coding conventions or EllisLabs rules.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.