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

Plugin: Eexcerpt - Strip HTML and limit words

Development and Programming

Marc Miller's avatar
Marc Miller
84 posts
16 years ago
Marc Miller's avatar Marc Miller
great plugin but i get an error Notice: Undefined offset: 70 in /plugins/pi.eexcerpt.php on line 80 any ideas? help?

I’m getting the same error. Well, similar in that the offset number is different.

Notice: Undefined offset: 16 in /plugins/pi.eexcerpt.php on line 80

I think the problem is when there are extra spaces at the end of the line. For example, I have my short description line to cut off after 16 words. My content manager put in a 14 word phrase, but during the copy and paste, he ended up putting 2 or 3 extra spaces at the end of the line. This caused the error. Once I removed the spaces, it works fine.

Is there some extra code you can add that will truncate any extra white space at the end of the line?

{exp:eexcerpt if_exceeds="16" stop_after="16"}
       
gridonic's avatar
gridonic
231 posts
16 years ago
gridonic's avatar gridonic
<?php
$var = 'with spaces   ';

$trimmed = trim($var);

echo($trimmed);
?>

should give ‘with spaces’ (without quotes), try adding the trim function where the plugin has troubles.

       
Ryan M.'s avatar
Ryan M.
1,511 posts
16 years ago
Ryan M.'s avatar Ryan M.

If peschehimself’s fix works, I can put that in the Plugin and update the “official” version.

       
mhulse's avatar
mhulse
329 posts
16 years ago
mhulse's avatar mhulse

Cool plugin… Sorry to resurrect old thread…

Would be cool to have control over the “…”. Why did you choose to not make that an

…

?

Other than that, this plugin has saved me some headache!!! Many thanks.

       
Paul Frost (orienteer)'s avatar
Paul Frost (orienteer)
389 posts
16 years ago
Paul Frost (orienteer)'s avatar Paul Frost (orienteer)

I’m getting the same error as alterracoffee.

Notice: Undefined offset: 20 in /home/xxxx/public_html/xxxx/plugins/pi.eexcerpt.php on line 80

I am using it to generate a meta_description from my intro field.

meta_description="{exp:eexcerpt if_exceeds="21" stop_after="20"}{std-intro}{/exp:eexcerpt}"

It looks like the reason for the message is because there are only 19 words. If I add a few words or reduce the if exceeds=”21” to 19 I don’t get the error.

My PHP is no good enough to work out what needs changing to catch this, any ideas?

       
Marc Miller's avatar
Marc Miller
84 posts
16 years ago
Marc Miller's avatar Marc Miller
If peschehimself’s fix works, I can put that in the Plugin and update the “official” version.

I finally got around to testing this and it seems to work great. I just added the TRIM function here (line 56):

function word_limiter_plus($str, $if_Exceeds = 500, $stop_after = 500, $the_link = "")
    {
    
    // strip out the tags first
    // http://us2.php.net/manual/en/function.strip-tags.php#68749
$searchcrap = array('@[removed]]*?>.*?[removed]@si',  // Strip out javascript
               '@<[\\/\\!]*?[^<>]*?>@si',            // Strip out HTML tags
               '@<style[^>]*?>.*?</style>@siU',    // Strip style tags properly
               '@<![\\s\\S]*?--[ \\t\\n\\r]*>@'          // Strip multi-line comments including CDATA
);
$str = preg_replace($searchcrap, '', $str);
$str = trim($str);
       
Morsekode's avatar
Morsekode
6 posts
16 years ago
Morsekode's avatar Morsekode

Sorry to resurrect an old thread, but we’re having the same problem that is talked about in this discussion. We’ve implemented the change that DoubleM talks about in the posts above, but to no avail. Is there a character in the copy somewhere that is causing the problem? We’ve tried a bunch of stuff, but nothing can get rid of this message:

Notice: Undefined offset: 40 in /home1/heroicp1/public_html/sys-heroic/plugins/pi.eexcerpt.php on line 80

You can see it for yourself here.

Thanks for your help!

       
Bruce2005's avatar
Bruce2005
536 posts
16 years ago
Bruce2005's avatar Bruce2005
To make decent excerpts, I needed something that stripped out all tags first and then limited the remaining words, all in one fell swoop, so I combined those functions into one

plugin.

I have a client using this for the meta description. Problem is that he has images first often and they are in the meta description….

Is there a way to remove image tags using this plugin?

{exp:eexcerpt if_exceeds="50" stop_after="40"}{summary}{/exp:eexcerpt}

thanks

       
Paul Frost (orienteer)'s avatar
Paul Frost (orienteer)
389 posts
16 years ago
Paul Frost (orienteer)'s avatar Paul Frost (orienteer)

Bruce I now use the Cleaner plugin from utilitEEs to produce my meta description. From things I read I don’t think it matters if the text goes over the character limit, they just get ignored.

I also use the Trimmer plugin from utilitEEs which has just added the option to trim before or after a specific character. I haven’t tried the two together but it might solve your problem.

       
Morsekode's avatar
Morsekode
6 posts
16 years ago
Morsekode's avatar Morsekode

Sorry to be a pain, but we’re hoping to go live on Monday and I’d really love to get rid of this error. Does anyone have any idea what might be causing this? Is there another plugin I could use that would both strip HTML tags out, and limit the words in order to create an excerpt? Thanks

Sorry to resurrect an old thread, but we’re having the same problem that is talked about in this discussion. We’ve implemented the change that DoubleM talks about in the posts above, but to no avail. Is there a character in the copy somewhere that is causing the problem? We’ve tried a bunch of stuff, but nothing can get rid of this message: Notice: Undefined offset: 40 in /home1/heroicp1/public_html/sys-heroic/plugins/pi.eexcerpt.php on line 80 You can see it for yourself here. Thanks for your help!
       
Paul Frost (orienteer)'s avatar
Paul Frost (orienteer)
389 posts
16 years ago
Paul Frost (orienteer)'s avatar Paul Frost (orienteer)

Did you check if the issue is resolved by my post above?

It doesn’t fix it if the fault is in the plugin in but it may allow you to find a way round it.

Or try TruncHTML.

       
Ryan M.'s avatar
Ryan M.
1,511 posts
16 years ago
Ryan M.'s avatar Ryan M.

Wow, I’ve been unsubscribed from this thread for some time, apparently.

I, too, think TruncHTML is a great plugin for what you’re trying to achieve and I use it myself.

However, I’ll take a quick look at this Eexcerpt plugin to see what might be causing the offset error.

       
Morsekode's avatar
Morsekode
6 posts
16 years ago
Morsekode's avatar Morsekode

Thanks a bunch guys, I really appreciate it. I agree with Paul in that the short ones that don’t have enough content might be the ones causing the problem. Seems strange though.

I’m looking into TruncHTML right now, though I know one reason that I liked the EExcerpt is that it both stripped P tags and everything else and limited words (not characters) but I think I could probably switch if I can’t figure out this issue.

P.S. I have no idea why I was writing in the third person (saying “we”) for awhile… I guess it was because I had to be logged into my companies account to be posting here… The “we” thing got weird though, had to switch. =)

       
Ryan M.'s avatar
Ryan M.
1,511 posts
16 years ago
Ryan M.'s avatar Ryan M.

This has been updated (and renamed). I put the latest version (1.1.0) at GitHub. There is a changelog there (scroll down). Let me know if it works for you.

       
Morsekode's avatar
Morsekode
6 posts
16 years ago
Morsekode's avatar Morsekode

Ryan, thanks so much for taking the time to look into this issue for me. My site is now working perfectly and should go live this week. (Should being the operative word there, I guess) I really appreciate it.

One thing I was going to bring up is that you may want to update both your plugin and your website’s instructions on how to use this plugin. It seems you changed the {exp:eexcerpt} tag to {exp:md_eexcerpt} which is fine and it didn’t take me that long to go into my templates and change the beginning and ending tags.

I notice the tags on your website haven’t been updated yet, which might be confusing. As well as the plugin itself when you browse to the plugins page talks about it and gives the wrong code at the end:

Wrap anything you want to be processed between the tag pairs. Works exactly like word_limit_plus, but strips tags.

{exp:md_eexcerpt if_exceeds="60" stop_after="40" append=" →" the_link="<a href='{title_permalink=weblog/comments}'>MORE...</a>"}text you want processed{/exp:eexcerpt}

This should include the md_eexcerpt at the end as well. Just letting you know.

       
1 2 3 4

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.