Loading ...
Sorry, an error occurred while loading the content.

[SimplePie] Re: Styling on Character Limit

Expand Messages
  • zach21uk
    I just want to elaborate further to avoid confusion: This is my code: http://pastie.org/566854 I am using this function:
    Message 1 of 14 , Aug 1, 2009
    View Source
    • 0 Attachment
      I just want to elaborate further to avoid confusion:

      This is my code: http://pastie.org/566854

      I am using this function: http://simplepie.org/wiki/tutorial/shorten_titles_and_descriptions - - - to limit the number of characters that my RSS Feed Displays, however, the function strips out "Smart" Punctuation and Replaces it with a single space in this string:

      // Convert 'smart' punctuation to 'dumb' punctuation, strip the HTML tags,
      // and convert all tabs and line-break characters to single spaces.
      $short_desc = trim(str_replace(array("\r","\n", "\t"), ' ', strip_tags($string)));


      I would like to keep the character limit, but stop the function from stripping out the line-breaks and new-lines, because its causing the content to display all on one line, ignoring any new lines that should be there.

      I tried modifying the function myself, but my understanding of PHP isnt great and it caused an error, so I am hoping someone here knows how to modify it so it leaves the line-breaks/new-lines, in there, but still limits the charcters.

      Thanks
      Zach

      --- In simplepie-support@yahoogroups.com, "zach21uk" <zach21uk@...> wrote:
      >
      > I understand what you are saying but not how to implement it:
      >
      > Here is my code as it stands right now:
      >
      > http://pastie.org/566854
      >
      > Where would I amend to include that, so that the lines are not stripped out of the code?
      >
      > Thanks
      >
      > --- In simplepie-support@yahoogroups.com, Ryan Parman <simplepie.support@> wrote:
      > >
      > > You have to use a linebreak character.
      > >
      > > echo 'This is my first line' . "\n" . 'This is my second line.'
      > >
      > > Notice the difference between single and double quotes. Control
      > > characters like this need to be double quoted.
      > >
      > >
      > > On 7/31/2009 1:06 AM, zach21uk wrote:
      > > > Can Anyone help with this last issue? pleasseee?!
      > > >
      > > > In simplepie-support@yahoogroups.com, "zach21uk"<zach21uk@> wrote:
      > > >
      > > >> Thats Perfect. The styling is there now. Just one more question however.....
      > > >>
      > > >> http://simplepie.org/wiki/tutorial/shorten_titles_and_descriptions
      > > >>
      > > >> All of the text is displaying on one line now, ignoring any new lines. How can I amend the script to leave new lines in there?
      > > >>
      > > >> --- In simplepie-support@yahoogroups.com, Ryan Parman<simplepie.support@> wrote:
      > > >>
      > > >>> This should resolve your issue: http://pastie.org/565358
      > > >>>
      > > >>> If it helps, here is a collection of tutorials called "PHP for the
      > > >>> absolute beginner." http://devzone.zend.com/node/view/id/627
      > > >>>
      > > >>> The first tutorial in the list, "Down the rabbit hole," goes over the
      > > >>> dot operator and the basics of string concatenation. http://devzone.zend.com/node/view/id/625
      > > >>>
      > > >>> Hope this helps! :)
      > > >>>
      > > >>> --
      > > >>> Ryan Parman
      > > >>> <http://ryanparman.com>
      > > >>>
      > > >>> Please don't email/IM me directly. That's why we have a mailing list. ;)
      > > >>>
      > > >>>
      > > >>>
      > > >>>
      > > >>>
      > > >>>
      > > >>> On Jul 30, 2009, at 6:46 AM, zach21uk wrote:
      > > >>>
      > > >>>
      > > >>>> Yes I have tried it as stated in that article.
      > > >>>>
      > > >>>> When I try to use the code you provided below, no content is
      > > >>>> displayed at all. Its just empty.
      > > >>>>
      > > >>>>
      > > >>>>
      > > >>>> --- In simplepie-support@yahoogroups.com, "bernhardbuhl@"
      > > >>>> <bernhardbuhl@> wrote:
      > > >>>>
      > > >>>>> Ah now I see I googled it. Did you took this from here?
      > > >>>>> http://simplepie.org/wiki/tutorial/shorten_titles_and_descriptions
      > > >>>>>
      > > >>>>> Did you setup the function shorten as it stands above?
      > > >>>>> And if then try
      > > >>>>>
      > > >>>>> echo "<div class='newscontent'>";
      > > >>>>> shorten($item->get_content(), 150);
      > > >>>>> echo "</div>";
      > > >>>>>
      > > >>>>> --- In simplepie-support@yahoogroups.com, "zach21uk"<zach21uk@>
      > > >>>>> wrote:
      > > >>>>>
      > > >>>>>> When I try to put it around the code, it either causes an error,
      > > >>>>>> or the styling does not take effect.
      > > >>>>>>
      > > >>>>>> This Causes an Error:
      > > >>>>>>
      > > >>>>>> echo '<div class="newscontent">'; shorten($item->get_content(),
      > > >>>>>> 150)'</div>';
      > > >>>>>>
      > > >>>>>> Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING
      > > >>>>>> in /home/hailingf/public_html/HF2009/includes/ourtopstory.php on
      > > >>>>>> line 52
      > > >>>>>>
      > > >>>>>>
      > > >>>>>> --- In simplepie-support@yahoogroups.com, "bernhardbuhl@"
      > > >>>>>> <bernhardbuhl@> wrote:
      > > >>>>>>
      > > >>>>>>> Don`t understand you really...why can't you put that around that
      > > >>>>>>> code?
      > > >>>>>>>
      > > >>>>>>> like
      > > >>>>>>> echo "<div class='headlines'>";
      > > >>>>>>>
      > > >>>>>>> <pseudocode>the code which ever you choose to take</pseudocode>
      > > >>>>>>>
      > > >>>>>>> echo "</div>";
      > > >>>>>>>
      > > >>>>>>> But maybe I get you wrong sorry for that my language skills are bad
      > > >>>>>>> kind regards
      > > >>>>>>>
      > > >>>>>>> --- In simplepie-support@yahoogroups.com, "zach21uk"<zach21uk@>
      > > >>>>>>> wrote:
      > > >>>>>>>
      > > >>>>>>>> That dosent really help me with the styling issue.
      > > >>>>>>>>
      > > >>>>>>>> I want to apply my "<div class="headlines"></div>" to the
      > > >>>>>>>> content string, as I had it before.
      > > >>>>>>>>
      > > >>>>>>>> --- In simplepie-support@yahoogroups.com, "bernhardbuhl@"
      > > >>>>>>>> <bernhardbuhl@> wrote:
      > > >>>>>>>>
      > > >>>>>>>>> I'm using a bit different code, so maybe you want to try this
      > > >>>>>>>>> out:
      > > >>>>>>>>>
      > > >>>>>>>>> $str = $item->get_content();
      > > >>>>>>>>>
      > > >>>>>>>>> function truncateString($str, $max, $rep = '...') {
      > > >>>>>>>>> if(strlen($str)> $max) {
      > > >>>>>>>>> $leave = $max - strlen($rep);
      > > >>>>>>>>> return substr_replace($str, $rep, $leave);
      > > >>>>>>>>> } else {
      > > >>>>>>>>> return $str;
      > > >>>>>>>>> }
      > > >>>>>>>>> }
      > > >>>>>>>>>
      > > >>>>>>>>> echo truncateString($str, 10);
      > > >>>>>>>>>
      > > >>>>>>>>> 10 means at the end the numbers of characters which shall be
      > > >>>>>>>>> displayed inclusive the "..." to show your members that there
      > > >>>>>>>>> normally is more to read.
      > > >>>>>>>>>
      > > >>>>>>>>> Well at least there is just more then one way and not usual to
      > > >>>>>>>>> make a function of it. Another way would be:
      > > >>>>>>>>>
      > > >>>>>>>>> $content = strlen($item->get_content());
      > > >>>>>>>>>
      > > >>>>>>>>> if ($content> 23) // How long should the content be
      > > >>>>>>>>> {
      > > >>>>>>>>> echo substr($item->get_content(),0,23); // Don't forget to
      > > >>>>>>>>> adjust the numbers of characters should be shown here too.
      > > >>>>>>>>> }
      > > >>>>>>>>>
      > > >>>>>>>>> else
      > > >>>>>>>>> {
      > > >>>>>>>>> echo $item->get_content();
      > > >>>>>>>>> }
      > > >>>>>>>>>
      > > >>>>>>>>> kind regards
      > > >>>>>>>>>
      > > >>>>>>>>> --- In simplepie-support@yahoogroups.com, "zach21uk"
      > > >>>>>>>>> <zach21uk@> wrote:
      > > >>>>>>>>>
      > > >>>>>>>>>> Hi There. Just a quicky.....
      > > >>>>>>>>>>
      > > >>>>>>>>>> I have just used this code which I found in another support
      > > >>>>>>>>>> post, to limit my content:
      > > >>>>>>>>>>
      > > >>>>>>>>>> echo shorten($item->get_content(), 150);
      > > >>>>>>>>>>
      > > >>>>>>>>>> This was my existing code:
      > > >>>>>>>>>>
      > > >>>>>>>>>> echo '<div class="newscontent">' . $item->get_content() . '</
      > > >>>>>>>>>> div>';
      > > >>>>>>>>>>
      > > >>>>>>>>>>
      > > >>>>>>>>>> How can I apply my styling to the shortend version? I have
      > > >>>>>>>>>> tried a couple of things but I get an error.
      > > >>>>>>>>>>
      > > >>>>>>>>>> Thanks
      > > >>>>>>>>>> Zach
      > > >>>>>>>>>>
      > > >>>>>>>>>>
      > > >>>>
      > > >>>>
      > > >>>> ------------------------------------
      > > >>>>
      > > >>>> Yahoo! Groups Links
      > > >>>>
      > > >>>>
      > > >>>>
      > > >>>>
      > > >
      > > >
      > > >
      > > >
      > > > ------------------------------------
      > > >
      > > > Yahoo! Groups Links
      > > >
      > > >
      > > >
      > > >
      > >
      >
    • Ryan Parman
      It s the strip_tags() function. The problem is that this function counts the number of characters to truncate to. HTML is counted in those characters. We
      Message 2 of 14 , Aug 4, 2009
      View Source
      • 0 Attachment
        It's the strip_tags() function. The problem is that this function
        counts the number of characters to truncate to. HTML is counted in
        those characters. We remove the HTML so that we can get an accurate
        character count. This is why everything is on a single line -- there
        is no HTML to break it all apart.

        If you can discover a reliable way to truncate characters while
        leaving HTML intact, we'd all appreciate knowing how to do this. :)

        --
        Ryan Parman
        <http://ryanparman.com>

        Please don't email/IM me directly. That's why we have a mailing list. ;)






        On Aug 1, 2009, at 4:45 AM, zach21uk wrote:

        > I just want to elaborate further to avoid confusion:
        >
        > This is my code: http://pastie.org/566854
        >
        > I am using this function: http://simplepie.org/wiki/tutorial/shorten_titles_and_descriptions
        > - - - to limit the number of characters that my RSS Feed Displays,
        > however, the function strips out "Smart" Punctuation and Replaces it
        > with a single space in this string:
        >
        > // Convert 'smart' punctuation to 'dumb' punctuation, strip the
        > HTML tags,
        > // and convert all tabs and line-break characters to single spaces.
        > $short_desc = trim(str_replace(array("\r","\n", "\t"), ' ',
        > strip_tags($string)));
        >
        >
        > I would like to keep the character limit, but stop the function from
        > stripping out the line-breaks and new-lines, because its causing the
        > content to display all on one line, ignoring any new lines that
        > should be there.
        >
        > I tried modifying the function myself, but my understanding of PHP
        > isnt great and it caused an error, so I am hoping someone here knows
        > how to modify it so it leaves the line-breaks/new-lines, in there,
        > but still limits the charcters.
        >
        > Thanks
        > Zach
        >
        > --- In simplepie-support@yahoogroups.com, "zach21uk" <zach21uk@...>
        > wrote:
        >>
        >> I understand what you are saying but not how to implement it:
        >>
        >> Here is my code as it stands right now:
        >>
        >> http://pastie.org/566854
        >>
        >> Where would I amend to include that, so that the lines are not
        >> stripped out of the code?
        >>
        >> Thanks
        >>
        >> --- In simplepie-support@yahoogroups.com, Ryan Parman
        >> <simplepie.support@> wrote:
        >>>
        >>> You have to use a linebreak character.
        >>>
        >>> echo 'This is my first line' . "\n" . 'This is my second line.'
        >>>
        >>> Notice the difference between single and double quotes. Control
        >>> characters like this need to be double quoted.
        >>>
        >>>
        >>> On 7/31/2009 1:06 AM, zach21uk wrote:
        >>>> Can Anyone help with this last issue? pleasseee?!
        >>>>
        >>>> In simplepie-support@yahoogroups.com, "zach21uk"<zach21uk@> wrote:
        >>>>
        >>>>> Thats Perfect. The styling is there now. Just one more question
        >>>>> however.....
        >>>>>
        >>>>> http://simplepie.org/wiki/tutorial/shorten_titles_and_descriptions
        >>>>>
        >>>>> All of the text is displaying on one line now, ignoring any new
        >>>>> lines. How can I amend the script to leave new lines in there?
        >>>>>
        >>>>> --- In simplepie-support@yahoogroups.com, Ryan
        >>>>> Parman<simplepie.support@> wrote:
        >>>>>
        >>>>>> This should resolve your issue: http://pastie.org/565358
        >>>>>>
        >>>>>> If it helps, here is a collection of tutorials called "PHP for
        >>>>>> the
        >>>>>> absolute beginner." http://devzone.zend.com/node/view/id/627
        >>>>>>
        >>>>>> The first tutorial in the list, "Down the rabbit hole," goes
        >>>>>> over the
        >>>>>> dot operator and the basics of string concatenation. http://devzone.zend.com/node/view/id/625
        >>>>>>
        >>>>>> Hope this helps! :)
        >>>>>>
        >>>>>> --
        >>>>>> Ryan Parman
        >>>>>> <http://ryanparman.com>
        >>>>>>
        >>>>>> Please don't email/IM me directly. That's why we have a mailing
        >>>>>> list. ;)
        >>>>>>
        >>>>>>
        >>>>>>
        >>>>>>
        >>>>>>
        >>>>>>
        >>>>>> On Jul 30, 2009, at 6:46 AM, zach21uk wrote:
        >>>>>>
        >>>>>>
        >>>>>>> Yes I have tried it as stated in that article.
        >>>>>>>
        >>>>>>> When I try to use the code you provided below, no content is
        >>>>>>> displayed at all. Its just empty.
        >>>>>>>
        >>>>>>>
        >>>>>>>
        >>>>>>> --- In simplepie-support@yahoogroups.com, "bernhardbuhl@"
        >>>>>>> <bernhardbuhl@> wrote:
        >>>>>>>
        >>>>>>>> Ah now I see I googled it. Did you took this from here?
        >>>>>>>> http://simplepie.org/wiki/tutorial/shorten_titles_and_descriptions
        >>>>>>>>
        >>>>>>>> Did you setup the function shorten as it stands above?
        >>>>>>>> And if then try
        >>>>>>>>
        >>>>>>>> echo "<div class='newscontent'>";
        >>>>>>>> shorten($item->get_content(), 150);
        >>>>>>>> echo "</div>";
        >>>>>>>>
        >>>>>>>> --- In simplepie-support@yahoogroups.com, "zach21uk"<zach21uk@>
        >>>>>>>> wrote:
        >>>>>>>>
        >>>>>>>>> When I try to put it around the code, it either causes an
        >>>>>>>>> error,
        >>>>>>>>> or the styling does not take effect.
        >>>>>>>>>
        >>>>>>>>> This Causes an Error:
        >>>>>>>>>
        >>>>>>>>> echo '<div class="newscontent">'; shorten($item-
        >>>>>>>>> >get_content(),
        >>>>>>>>> 150)'</div>';
        >>>>>>>>>
        >>>>>>>>> Parse error: syntax error, unexpected
        >>>>>>>>> T_CONSTANT_ENCAPSED_STRING
        >>>>>>>>> in /home/hailingf/public_html/HF2009/includes/
        >>>>>>>>> ourtopstory.php on
        >>>>>>>>> line 52
        >>>>>>>>>
        >>>>>>>>>
        >>>>>>>>> --- In simplepie-support@yahoogroups.com, "bernhardbuhl@"
        >>>>>>>>> <bernhardbuhl@> wrote:
        >>>>>>>>>
        >>>>>>>>>> Don`t understand you really...why can't you put that around
        >>>>>>>>>> that
        >>>>>>>>>> code?
        >>>>>>>>>>
        >>>>>>>>>> like
        >>>>>>>>>> echo "<div class='headlines'>";
        >>>>>>>>>>
        >>>>>>>>>> <pseudocode>the code which ever you choose to take</
        >>>>>>>>>> pseudocode>
        >>>>>>>>>>
        >>>>>>>>>> echo "</div>";
        >>>>>>>>>>
        >>>>>>>>>> But maybe I get you wrong sorry for that my language skills
        >>>>>>>>>> are bad
        >>>>>>>>>> kind regards
        >>>>>>>>>>
        >>>>>>>>>> --- In simplepie-support@yahoogroups.com,
        >>>>>>>>>> "zach21uk"<zach21uk@>
        >>>>>>>>>> wrote:
        >>>>>>>>>>
        >>>>>>>>>>> That dosent really help me with the styling issue.
        >>>>>>>>>>>
        >>>>>>>>>>> I want to apply my "<div class="headlines"></div>" to the
        >>>>>>>>>>> content string, as I had it before.
        >>>>>>>>>>>
        >>>>>>>>>>> --- In simplepie-support@yahoogroups.com, "bernhardbuhl@"
        >>>>>>>>>>> <bernhardbuhl@> wrote:
        >>>>>>>>>>>
        >>>>>>>>>>>> I'm using a bit different code, so maybe you want to try
        >>>>>>>>>>>> this
        >>>>>>>>>>>> out:
        >>>>>>>>>>>>
        >>>>>>>>>>>> $str = $item->get_content();
        >>>>>>>>>>>>
        >>>>>>>>>>>> function truncateString($str, $max, $rep = '...') {
        >>>>>>>>>>>> if(strlen($str)> $max) {
        >>>>>>>>>>>> $leave = $max - strlen($rep);
        >>>>>>>>>>>> return substr_replace($str, $rep, $leave);
        >>>>>>>>>>>> } else {
        >>>>>>>>>>>> return $str;
        >>>>>>>>>>>> }
        >>>>>>>>>>>> }
        >>>>>>>>>>>>
        >>>>>>>>>>>> echo truncateString($str, 10);
        >>>>>>>>>>>>
        >>>>>>>>>>>> 10 means at the end the numbers of characters which shall
        >>>>>>>>>>>> be
        >>>>>>>>>>>> displayed inclusive the "..." to show your members that
        >>>>>>>>>>>> there
        >>>>>>>>>>>> normally is more to read.
        >>>>>>>>>>>>
        >>>>>>>>>>>> Well at least there is just more then one way and not
        >>>>>>>>>>>> usual to
        >>>>>>>>>>>> make a function of it. Another way would be:
        >>>>>>>>>>>>
        >>>>>>>>>>>> $content = strlen($item->get_content());
        >>>>>>>>>>>>
        >>>>>>>>>>>> if ($content> 23) // How long should the content be
        >>>>>>>>>>>> {
        >>>>>>>>>>>> echo substr($item->get_content(),0,23); // Don't forget
        >>>>>>>>>>>> to
        >>>>>>>>>>>> adjust the numbers of characters should be shown here too.
        >>>>>>>>>>>> }
        >>>>>>>>>>>>
        >>>>>>>>>>>> else
        >>>>>>>>>>>> {
        >>>>>>>>>>>> echo $item->get_content();
        >>>>>>>>>>>> }
        >>>>>>>>>>>>
        >>>>>>>>>>>> kind regards
        >>>>>>>>>>>>
        >>>>>>>>>>>> --- In simplepie-support@yahoogroups.com, "zach21uk"
        >>>>>>>>>>>> <zach21uk@> wrote:
        >>>>>>>>>>>>
        >>>>>>>>>>>>> Hi There. Just a quicky.....
        >>>>>>>>>>>>>
        >>>>>>>>>>>>> I have just used this code which I found in another
        >>>>>>>>>>>>> support
        >>>>>>>>>>>>> post, to limit my content:
        >>>>>>>>>>>>>
        >>>>>>>>>>>>> echo shorten($item->get_content(), 150);
        >>>>>>>>>>>>>
        >>>>>>>>>>>>> This was my existing code:
        >>>>>>>>>>>>>
        >>>>>>>>>>>>> echo '<div class="newscontent">' . $item-
        >>>>>>>>>>>>> >get_content() . '</
        >>>>>>>>>>>>> div>';
        >>>>>>>>>>>>>
        >>>>>>>>>>>>>
        >>>>>>>>>>>>> How can I apply my styling to the shortend version? I
        >>>>>>>>>>>>> have
        >>>>>>>>>>>>> tried a couple of things but I get an error.
        >>>>>>>>>>>>>
        >>>>>>>>>>>>> Thanks
        >>>>>>>>>>>>> Zach
        >>>>>>>>>>>>>
        >>>>>>>>>>>>>
        >>>>>>>
        >>>>>>>
        >>>>>>> ------------------------------------
        >>>>>>>
        >>>>>>> Yahoo! Groups Links
        >>>>>>>
        >>>>>>>
        >>>>>>>
        >>>>>>>
        >>>>
        >>>>
        >>>>
        >>>>
        >>>> ------------------------------------
        >>>>
        >>>> Yahoo! Groups Links
        >>>>
        >>>>
        >>>>
        >>>>
        >>>
        >>
        >
        >
        >
        >
        > ------------------------------------
        >
        > Yahoo! Groups Links
        >
        >
        >
      Your message has been successfully submitted and would be delivered to recipients shortly.