3v4l.org

run code in 300+ PHP versions simultaneously
<?php $xml = '<?xml version="1.0" encoding="utf-8"?> <products> <item> <reference>00001</reference> <other_string>PRODUCT 1</other_string> <brand>BRAND 1</brand> <promo>YES</promo> </item> <item> <reference>00002</reference> <other_string>PRODUCT 2</other_string> <brand>BRAND 2</brand> <promo>YES</promo> </item> <item> <reference>00003</reference> <other_string>PRODUCT 3</other_string> <brand>BRAND 3</brand> <promo>NO</promo> </item> <item> <reference>00004</reference> <other_string>PRODUCT 4</other_string> <brand>BRAND 4</brand> <promo>NO</promo> </item> <item> <reference>00005</reference> <other_string>PRODUCT 5</other_string> <brand>BRAND 5</brand> <promo>YES</promo> </item> </products>'; $doc = new DOMDocument(); $doc->loadXML($xml); foreach ($doc->getElementsByTagName('promo') as $ele) { $newnode = $doc->createElement('newnode'); $newnode->nodeValue = $ele->nodeValue == 'YES' ? 1 : 0; $ele->parentNode->appendChild($newnode); } echo $doc->saveXML();
Output for git.master, git.master_jit, rfc.property-hooks
<?xml version="1.0" encoding="utf-8"?> <products> <item> <reference>00001</reference> <other_string>PRODUCT 1</other_string> <brand>BRAND 1</brand> <promo>YES</promo> <newnode>1</newnode></item> <item> <reference>00002</reference> <other_string>PRODUCT 2</other_string> <brand>BRAND 2</brand> <promo>YES</promo> <newnode>1</newnode></item> <item> <reference>00003</reference> <other_string>PRODUCT 3</other_string> <brand>BRAND 3</brand> <promo>NO</promo> <newnode>0</newnode></item> <item> <reference>00004</reference> <other_string>PRODUCT 4</other_string> <brand>BRAND 4</brand> <promo>NO</promo> <newnode>0</newnode></item> <item> <reference>00005</reference> <other_string>PRODUCT 5</other_string> <brand>BRAND 5</brand> <promo>YES</promo> <newnode>1</newnode></item> </products>

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
32.88 ms | 408 KiB | 5 Q