Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

RSS2HTML Wordwrap

Posted on 2010-01-02
4
Medium Priority
?
375 Views
Last Modified: 2013-11-18
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
0
Comment
Question by:Gregg Battaglia
  • 3
4 Comments
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 1500 total points
ID: 26164094
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
 

Author Comment

by:Gregg Battaglia
ID: 26164164
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
 

Author Comment

by:Gregg Battaglia
ID: 26164278
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
 

Author Closing Comment

by:Gregg Battaglia
ID: 31672048
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

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The first step to building an amazing About page is to figure out what you want the page to say about your company. You then must grab the attention of the reader, boast a bit, tell a story and let others brag about you. With a little bit of thought…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question