Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Edit XML with PHP Re: Edit XML with PHP

#78083
Capt Otis
Member

Perfect. Now here is a quick xml file writer…

Code:
formatOutput = true;

$r = $doc->createElement( “pricing” );//creates $doc->appendChild( $r );

for( $i = 0, $c = count($title); $i < $c; $i++ ) {//loops through your vars... $b = $doc->createElement( “package” );//creates

$a1 = $doc->createElement( “title” );//creates <br /> $a1->appendChild($doc->createTextNode( $title[$i] ) );//places $title[$i]’s value into <br /> $b->appendChild( $a1 );//closes

$a2 = $doc->createElement( “price” );
$a2->appendChild($doc->createTextNode( $price[$i] ) );
$b->appendChild( $a2 );

$a3 = $doc->createElement( “description” );
$a3->appendChild($doc->createTextNode( $description[$i] ) );
$b->appendChild( $a3 );

$r->appendChild( $b );//closes }

$doc->save($xmlLoc);//and save.

?>

I actually didn’t test this, because I don’t want to take the time to set everything up but all looks in order. I commented out so you can see what I did, see if you can figure out how things work. Actually simple once you get it. Modify if needed, best of luck.