We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Limiting charachters in sidebar

Development and Programming

Kevpool1's avatar
Kevpool1
9 posts
16 years ago
Kevpool1's avatar Kevpool1

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.

       
leadsuccess's avatar
leadsuccess
408 posts
16 years ago
leadsuccess's avatar leadsuccess

This is the one I use as it’s in your list http://expressionengine.com/downloads/details/trunchtml/, are you talking strict validation?

       
baboonbrand's avatar
baboonbrand
14 posts
16 years ago
baboonbrand's avatar baboonbrand

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
       
silenz's avatar
silenz
1,648 posts
16 years ago
silenz's avatar silenz

In case you end up using TruncHTML, please note that the version found under http://expressionengine.com/downloads/details/trunchtml/ is outdated and a current version is found under http://utilitees.silenz.org/index.php/addons/software/trunchtml/.

       
Kevpool1's avatar
Kevpool1
9 posts
16 years ago
Kevpool1's avatar Kevpool1

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.

       
baboonbrand's avatar
baboonbrand
14 posts
16 years ago
baboonbrand's avatar baboonbrand

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.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.