Pravin Pravin - 7 months ago 36
PHP Question

Convert array in a variable and manipulate it to create XML file in php

$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);

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');

I want my XML output to be like

<?xml version="1.0"?>


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);