I am display mysql data in xml file using php.
there I used this one in here i want to give line breaks .if we give line breaks that will display line break tag in content ..we have to give html tags .but we dont show them in xml content ...
the output is coming like this..
At the same time I want to remove that empty p tags also ...that is.
<![CDATA[ <p> </p>]]>
this is the code i have written for xml ...
please solve this problems
header("Content-Type: application/xml; charset=utf-8");
date_default_timezone_set("Asia/Calcutta");
$this->view->data=$this->CallModel('posts')- >GalleryAndContent();
$xml = '
';
$xml.='Thehansindia
http://www.thehansindia.com
Newspaper with a difference';
foreach($this->view->data as $values)
{
$output=strip_tags($values['text_data'],"
"); $output = preg_replace('/(<[^>]+) style=".?"/i', '$1',$output); $output = preg_replace('/(<[^>]+) class=".?"/i', '$1', $output); $output=preg_replace( '/style=(["\'])[^\1]?\1/i', '', $output, -1 ); $output=preg_replace("/<([a-z][a-z0-9])[^>]*?(/?)>/i",'',$output); $output=str_replace(array("",""),array("
","
"),$output); $output=str_replace(array("",""),array("","
"),,$output); //$xml.="<CONTENT>"."<![CDATA[".$output."]]>"."</CONTENT>
$xml.= '<item>';
$dom = new DOMDocument;
@$dom->loadHTML($output);
$xml.="<CONTENT>";
foreach ($dom->getElementsByTagName('p') as $tag){
//$tag->nodeValue=str_replace("<![CDATA[ <p> </p> ]]>","",$tag->nodeValue);
if(!empty($tag->nodeValue)){
//$tag->nodeValue=str_replace("<![CDATA[ <p>& & &</p> ]]>","",$tag->nodeValue);
$xml.="<![CDATA["."<p>".stripslashes($tag->nodeValue)."</p>"."]]>";
}
}
$xml.="</CONTENT>";
$xml.= ' </item>';
}