Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php XML中的HTML标记`_Php_Html_Xml - Fatal编程技术网

Php XML中的HTML标记`

Php XML中的HTML标记`,php,html,xml,Php,Html,Xml,我在从PHP导出XML文件时遇到问题。它没有应用结束标记,这似乎让我以HTML标记结束 <!--?xml version="1.0"?--> <html> <head> </head> <body> <entries> <entry> <img>1030.jpg <comment>Jean</comm

我在从PHP导出XML文件时遇到问题。它没有应用结束标记,这似乎让我以HTML标记结束

<!--?xml version="1.0"?-->
<html>
  <head>
  </head>
    <body>
      <entries>
        <entry>
          <img>1030.jpg
          <comment>Jean</comment>
        </entry>
      </entries>
    </body>
</html>

1030.jpg
斜纹棉布
下面是创建它的PHP部分

<?php
  include_once "config.php";
  mysql_connect($dbhost, $dbuser, $dbpasswd);
  mysql_select_db($dbname) or die ("Cannot select db" . mysql_error());
  session_start();      
$query = "SELECT * FROM test_table WHERE state = 1 LIMIT 10";       
$result = mysql_query($query) or die(mysql_error());

$xml = new SimpleXMLElement('<entries/>');

while ($row = mysql_fetch_array($result, MYSQL_NUM)) { 
    $values = implode(",", $row);
    list($ep_id, $image, $origimg,  $actid , $date, $approve, $apptime, $fbid, $custid, $title, $comment, $admincom, $link, $lang, $video, $rate, $finalist, $brand, $day, $source) = explode(",", $values);
    $entry = $xml->addChild('Entry');
        $entry->addChild('link', $lang);
        $entry->addChild('comment', $comment);
}

  print($xml->asXML());


?>

我想让它生成一个我可以引用的XML文件。我不确定HTML标签来自哪里,但他们给了我一个错误代码


<?php
  header("Content-type: text/xml"); 
  include_once "config.php";
  mysql_connect($dbhost, $dbuser, $dbpasswd);
  mysql_select_db($dbname) or die ("Cannot select db" . mysql_error());
  session_start();      
$query = "SELECT * FROM `test_table` WHERE source = 'youtube'";     
$result = mysql_query($query) or die(mysql_error());

$xml = new XMLWriter();

$xml->openURI("php://output");
$xml->startDocument();
$xml->setIndent(true);

$xml->startElement('Entries');

while ($row = mysql_fetch_assoc($result)) {
    $xml->startElement('entry');

      $xml->writeElement('id', $row["ep_id"]);
        $xml->writeElement('title', $row["ep_title"]);
        $xml->writeElement('thumb', '<img src="http://img.youtube.com/vi/'.$row["ep_youtubeid"].'/2.jpg" width="60px" /><span style="margin: -20px 0 0 5px;">'.$row["ep_title"].'</span>');
        $xml->writeElement('content', '<iframe class="youtube-player" type="text/html" width="310" height="170" src="http://www.youtube.com/embed/'.$row["ep_youtubeid"].'" frameborder="0"></iframe><div style="text-align:left;color:#fff;"><strong>Title: </strong>' . $row["ep_title"].'</div><div style="text-align:left;color:#fff;"><strong>Comments: </strong>' . $row["ep_comments"].'</div><div class="fb-login-button">Login with Facebook</div>');

    $xml->endElement();
};

$xml->endElement();

$xml->flush();


?>


检查脚本的原始输出。在您的例子中,HTML标记可以是PHP警告/通知。在示例代码中,您添加了一个链接子项,但示例输出是img。您是否删除了错误的代码?您的list/explode操作也可以简化为each(),这样就不需要执行中间字符串解析步骤(并且允许在任何字段中使用)list($ep_id、$image、$origimg、$actid、$date、$approve、$apptime、$fbid、$custid、$title、$comment、$admincom、$link、$lang、$video、$rate、$finalist、$brand、$day、$source)=每个($value);是的,我有错误的值,我正在检查('img',$img)是它没有关闭的原因。请检查脚本的原始输出。在您的示例代码中,HTML标记可以是PHP警告/通知。在您的示例代码中,您添加了一个链接子项,但示例输出是img。您是否删除了错误的代码?您的列表/分解操作也可以简化为each(),以消除执行中间字符串解析步骤的需要(并允许在任何字段中)列表($ep_id、$image、$origimg、$actid、$date、$apptime、$fbid、$custid、$title、$comment、$admincom、$link、$lang、$video、$rate、$finalist、$brand、$day、$source)=每个($value);是的,我在那里有错误的值,我正在检查('img',$img)这就是它不关门的原因。