首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >数组到xml或xspf使xspf文件嵌入vlc lugin播放列表。

数组到xml或xspf使xspf文件嵌入vlc lugin播放列表。
EN

Stack Overflow用户
提问于 2015-12-17 12:51:09
回答 2查看 336关注 0票数 0

我正在尝试输入复选框列表当前文件夹.mp3获取使用gob函数glob_grace列出音频文件使用复选框然后复选框

获取数组复选框值使xspf文件使用php

我将数组代码全部写入xml。

但是小的错误,请任何人告诉我什么错误和哪里发生的错误!

代码语言:javascript
复制
<?php   
foreach (glob("*.{mp3,mp4}", GLOB_BRACE) as $filename) {
    $values = $filename ;
    echo "<form action='p.php' method='POST'>";
    echo "<input type='checkbox' name='foo[]' value='$values'>$values <hr>";    

}
    echo "<input type='submit' name='submit' value='Submit'>";
    echo "</form>";

?>

它将转到下一页

代码语言:javascript
复制
<?php
        $g = $_POST['foo'];
       $cnt = count($g);
        //function definition to convert array to xml
function array_to_xml($array, &$xml_user_info) {
    for ($i=0 ; $i < $cnt ;$i++)
    {
        $track = $xml_user_info->addChild('track');
        $track->addChild("location",$array[$i]);
     }                                       

}

//creating object of SimpleXMLElement
$xml_user_info = new SimpleXMLElement("<?xml version=\"1.0\"?><trackList></trackList>");

//function call to convert array to xml
array_to_xml($g,$xml_user_info);

//saving generated xml file
$xml_file = $xml_user_info->asXML('users.xspf');

//success and error message based on xml creation
if($xml_file){
    echo 'XML file have been generated successfully.';
}else{
    echo 'XML file generation error.';
}
?>

请给我答案解决方案工作代码

提前感谢

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-12-17 16:53:22

如果glob("*.{mp3,mp4}", GLOB_BRACE)返回一个具有多个项的数组,则需要多次生成<form action='p.php' method='POST'>标记。

也许您可以将表单声明移到foreach之外。

如果我提交了表单并加载了p.php,我会收到以下通知:

注意:未定义变量: cnt

您正在使用$cnt = count($g);对项目进行计数,但也可以传递此$g并在function array_to_xml中计数其项。

我认为,如果您想从$_POST['foo']中获得值,首先应该检查它是否是POST,然后检查是否设置了$_POST['foo']

也许这个设置可以帮助您:

代码语言:javascript
复制
<?php

//function definition to convert array to xml
function array_to_xml($array, &$xml_user_info)
{
    for ($i = 0; $i < count($array); $i++) {
        $track = $xml_user_info->addChild('track');
        $track->addChild("location", $array[$i]);
    }
}

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    if (isset($_POST['foo'])) {
        $g = $_POST['foo'];

        //creating object of SimpleXMLElement
        $xml_user_info = new SimpleXMLElement("<?xml version=\"1.0\"?><trackList></trackList>");

        //function call to convert array to xml
        array_to_xml($g, $xml_user_info);

        //saving generated xml file
        $xml_file = $xml_user_info->asXML('users.xspf');

        //success and error message based on xml creation
        if ($xml_file) {
            echo 'XML file have been generated successfully.';
        } else {
            echo 'XML file generation error.';
        }
    }
}
?>
票数 1
EN

Stack Overflow用户

发布于 2020-06-15 23:47:43

代码语言:javascript
复制
$xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><playlist></playlist>');
$trackList = $xml->addChild('trackList');
foreach ($_POST['files'] as $video) {
    $track = $trackList->addChild('track');
    $track->addChild('location', 'file://'.$tmp_dir.'/'.$video['path']);
    $track->addChild('title', $video['name']);
}
file_put_contents('playlist.xspf',$xml->asXML());
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34335067

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档