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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?