Gregg Battaglia
asked on
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
<?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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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('rss2 html.php') ;
function get_include_contents($file name) {
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) ; ?>
first add to the top of the page:
<?php
$rssfeed = get_include_contents('rss2
function get_include_contents($file
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) ; ?>
ASKER
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.
ASKER
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.