-1

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>';
                    }

enter image description here

user3445862
  • 59
  • 1
  • 9
  • 4
    Please consider supplying actual code instead of an image. It's much work work for your potential helper to recreate sample code if s/he can't copy-paste from your supplied example. – kojiro Mar 26 '14 at 13:17
  • Please do not post screenshot of code but provide code instead. – ek9 Mar 26 '14 at 13:32

1 Answers1

0

Example:

//Next replace all new lines with the unicode:
$xml = str_replace("\n","&#10;", $xml);

Reference Link

Community
  • 1
  • 1
SagarPPanchal
  • 9,839
  • 6
  • 34
  • 62