0

it is not passing url value from php to xml conversion

Warning: SimpleXMLElement::__construct(): Entity: line 141: parser error : EntityRef: expecting ';' in /home/u395985035/public_html/ddd/ddd.php on line 34

Warning: SimpleXMLElement::__construct(): http://teko.gogo.com/gtw_c?tem_id=844&erw_id=44545 in /home/u395985035/public_html/ddd/ddd.php on line 34

Warning: SimpleXMLElement::__construct(): ^ in /home/u395985035/public_html/ddd/ddd.php on line 34

Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /home/u395985035/public_html/ddd/ddd.php:34 Stack trace: #0 /home/u395985035/public_html/ddd/ddd.php(34): SimpleXMLElement->__construct('\n\t\t

    <?php

  include("config.php"); 

    $sql = "SELECT * FROM table1";
    $q   = mysqli_query($conn,$sql) or die(mysql_error());
    $xml = "<demo1>\n\t\t";

    while($r = mysqli_fetch_array($q))   {
      $xml .= "<t_view>\n\t";
      $xml .= "<l1>".$r['id']."</l1>\n\t\t";  
      $xml .= "<l2>".$r['link1']."</l2>\n\t\t";
      $xml .= "</t_view>\n\t";  
    }

       $xml .= "</demo1>\n\t\t";
    $sxe = new SimpleXMLElement($xml);
    $sxe->asXML("ddd.xml");

 /* I am parsing url link with parameters in $r['link1'] */
?>
ArK
  • 20,698
  • 67
  • 109
  • 136
JnT
  • 21
  • 8

1 Answers1

0

Okay don't encode your url just try this , I have tested and it is working.

while($r = mysqli_fetch_array($q))   {
      $xml .= "<t_view>\n\t";
      $xml .= "<l1>".$r['id']."</l1>\n\t\t";  
      $xml .= "<l2>".preg_replace('#&(?=[a-z_0-9]+=)#', '&amp;', $r['link1'])."</l2>\n\t\t";
      $xml .= "</t_view>\n\t";  
    }
Sachin Vairagi
  • 4,894
  • 4
  • 35
  • 61