RSS2HTML Wordwrap

I am using the RSS2HTML processing file to display an RSS feed on a web page. The RSS2HTML.php is from the feedforall.com web site. It is a free download but I don't want to just paste their code on here. The problem I am having is that I need it to use a word wrap  function that I use which is :

<?php
// This function will insert the 'wbr' (optional linebreak) tag
// to wrap words in $string longer than 10 characters,
// but will not break inside HTML tags
function mywordwrap($string)
{
$length = strlen($string);

for ($i=0; $i<=$length; $i=$i+1)
    {
    $char = substr($string, $i, 1);
    if ($char == "<")
        $skip=1;
    elseif ($char == ">")
        $skip=0;
    elseif ($char == " ")
        $wrap=0;

    if ($skip==0)
        $wrap=$wrap+1;

    $returnvar = $returnvar . $char;

    if ($wrap>32) // alter this number to set the maximum word length
        {
        $returnvar = $returnvar . "<wbr>";
        $wrap=0;
        }
    }

return $returnvar;

}
?>

On the page that I am displaying the rss feed on I just use <?php include("rss2html.php"); ?> to bring in the rss feed. Is there a way to use the wordwrap function on this page or in their php script? any help would be great!!!

Thanks
Gregg
Gregg BattagliaAsked:
Who is Participating?
 
Ray PaseurCommented:
What fields of the RSS do you want to use "wordwrap" on (Title? Description?)  I think you might need to parse the RSS into strings, apply the function to the strings and then reassemble the RSS.  Not sure without some test data to apply the function to - you can have HTML inside RSS, so it is not completely straightforward.

Can you show us a test data string, please.
0
 
Gregg BattagliaAuthor Commented:
I want to apply the wordwrap to the description field and maybe the title field as well. The file they give is not that strait forward... how could I take the output of the rss2html.php file and use the wordwrap function listed above on it? Right now I am using a simple include of the rss2html.php to display it on the page. I want to apply the wordwrap to the output. How can I parse the output then apply the function? sorry I still kinda new to the php uses.

Thanks

PS what kind of test data string do you need? the page is located at http://iphone.havenzone.com/classifieds/index.php

Basically since I am trying to display this on an iphone I need it to linebreak anything over 32 chars to fit properly on the screen.
0
 
Gregg BattagliaAuthor Commented:
ok, I figured it out... if you want to display the RSS feed on a small screen mobile device like an iphone you should do this so if any words are over 32 chars it will go to the next line...

first add to the top of the page:

<?php
$rssfeed = get_include_contents('rss2html.php');
function get_include_contents($filename) {
    if (is_file($filename)) {
        ob_start();
        include $filename;
        $contents = ob_get_contents();
        ob_end_clean();
        return $contents;
    }
    return false;
}
?>

Then this:

<?php
// This function will insert the 'wbr' (optional linebreak) tag
// to wrap words in $string longer than 10 characters,
// but will not break inside HTML tags
function mywordwrap($string)
{
$length = strlen($string);

for ($i=0; $i<=$length; $i=$i+1)
    {
    $char = substr($string, $i, 1);
    if ($char == "<")
        $skip=1;
    elseif ($char == ">")
        $skip=0;
    elseif ($char == " ")
        $wrap=0;

    if ($skip==0)
        $wrap=$wrap+1;

    $returnvar = $returnvar . $char;

    if ($wrap>32) // alter this number to set the maximum word length
        {
        $returnvar = $returnvar . "<wbr>";
        $wrap=0;
        }
    }

return $returnvar;

}
?>

then in the body of the page where you want to display the rss feed just add this:

<?php echo mywordwrap($rssfeed) ; ?>
0
 
Gregg BattagliaAuthor Commented:
It pointed me in the right direction and gave me an idea of what to look into... then I found it on the php web site.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.