Please can somebody provide some information or look at my PHP to see where I'm going wrong.

Background info: I download a RSS feed from a website and then remove all unwanted information and place it into a custom XML file and then this is feed into a flash website after cutting it down to the first 32 elements.

This worked perfectly fine until they recently introduced multiple line breaks in the title element of the RSS and I need to remove them.

<?php 
// Get the RSS feed and load it into a SimpleXML object 
$file = file_get_contents('http://www.movies.com/rss'); 
$xml  = simplexml_load_string($file); 

// Create a new instance of domdocument 
$dom  = new DOMDocument('1.0', 'iso-8859-1'); 
$dom->preserveWhiteSpace = false; 
$dom->formatOutput = true; 
// Set the root element 
$root = $dom->createElement('items'); 

// Pull all of the titles, descriptions, and links from $file 
foreach ($xml->channel->item as $item) { 
  $title = $item->title; 
  $desc  = $item->description; 
  $url   = $item->link; 

  $element = $dom->createElement('item'); 
  $element->setAttribute('title', $title); 
  $element->setAttribute('description', $desc); 
  $element->setAttribute('url', $url); 
  $element = $root->appendChild($element); 
} 

// Build a new XML file 
$dom->appendChild($root); 
$xml = $dom->saveXML(); 
if ($dom->loadXML($xml)) { 
  $dom->save('input1.xml'); 
} 

// Strip out line feeds
$fp1 = fopen("input1.xml", "r"); 
$xm2  = simplexml_load_string($fp1);
$xm2 = str_replace("
","",$xm2);
$fp2 = fopen('output1.xml', 'w');
fputs($fp2, file_get_contents($xml2)); 
fclose($fp2); 

//Read output1.xml and strip out first 32 elements and put them into output2.xml
$num = 32; // Read max 32 lines 
$fp3 = fopen("output1.xml", "r"); 

if($fp3) { 
    $cnt = 0; 
    $text = ''; 
    while ($cnt<$num && !($reached_eof = feof($fp3)) ){//$num lines or end of file 
        $text .= fgets($fp3, 4096); 
        $cnt++;
    }
        fclose($fp3); 
} 
$fp4 = fopen('output2.xml', 'w');
if (!$reached_eof)
    $text .= '</items>';
    fwrite($fp4, $text);
fclose($fp3);
?>

Please note that the line breaks are in html entity and only show up as blank space or LF (line Feeds). Any advise on what I'm doing wrong would be greatly appreciated.

Below is an example of the input.xml file, where I'm trying to remove the LF.

<?xml version="1.0" encoding="iso-8859-1"?>
<items>
  <item title="



















movie name" description="movie description" url="http://www.movies.com/moviename/"/>
</items>
    Write a Reply...