duanneng2014 2016-11-22 10:03
浏览 19
已采纳

转换变量中的数组并操纵它以在php中创建XML文件

    $bday = $f['date_of_birth']; //it outputs-> 20102016

So I tried using preg_split() or even explode() but was of no help

    $str = $bday;
    $chars = preg_split('//', $str, -1, PREG_SPLIT_NO_EMPTY);
    print_r($chars[0]);

I want to use $bday as a nodeValue in DOMDocument to create XML file

    $doc = new DOMDocument();
    $doc->formatOutput = true;

    $root = $doc->createElement('StudentDetails');
    $root = $doc->appendChild($root);

    $ele1 = $doc->createElement('DateOfBirth');
    $ele1->nodeValue=$bday;
    $root->appendChild($ele1);

I want my XML output to be like

    <?xml version="1.0"?>
    <StudentDetails>
         <DateOfBirth>20/10/2016</DateOfBirth>
    </StudentDetails> 
  • 写回答

4条回答 默认 最新

  • dshfjsh_5455 2016-11-22 10:07
    关注

    If the date is always DDMMYYYY you could insert slashes with preg_replace.

    $bday = preg_replace('/(\d\d)(\d\d)(\d\d\d\d)/', "$1/$2/$3", $bday);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥30 最小化遗憾贪心算法上界
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝