3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $teste = ' <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> <composition ownerId="9" ownerName="Innom" version="0.2" id="7360b6258a0336d14cbce7246a1e9c46" name="I Wont Give It Away"> <tracks> <track id="1" userId="9" userName="Innom" collaborationId="0" trackType="9" volume="100"></track> <track id="1" userId="9" userName="Innom" collaborationId="0" trackType="9" volume="100"></track> <track id="1" userId="9" userName="Innom" collaborationId="0" trackType="9" volume="100"></track> </tracks> <records> <record id="63e7a25d022e2a29b149b6686c446871" userId="9" frames="9668736"/> <record id="63e7a25d022e2a29b149b6686c446871" userId="9" frames="9668736"/> <record id="63e7a25d022e2a29b149b6686c446871" userId="9" frames="9668736"/> </records> </composition> </rss> '; $asd = substr_count($teste, '<record id'); for ($i = 1; $i <= $asd; $i++) { $teste = str_replace('collaborationId="0"', 'collaborationId="'.$i.'"', $teste, $i); } echo $teste;
Output for 4.3.0 - 4.3.1, 5.0.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> <composition ownerId="9" ownerName="Innom" version="0.2" id="7360b6258a0336d14cbce7246a1e9c46" name="I Wont Give It Away"> <tracks> <track id="1" userId="9" userName="Innom" collaborationId="1" trackType="9" volume="100"></track> <track id="1" userId="9" userName="Innom" collaborationId="1" trackType="9" volume="100"></track> <track id="1" userId="9" userName="Innom" collaborationId="1" trackType="9" volume="100"></track> </tracks> <records> <record id="63e7a25d022e2a29b149b6686c446871" userId="9" frames="9668736"/> <record id="63e7a25d022e2a29b149b6686c446871" userId="9" frames="9668736"/> <record id="63e7a25d022e2a29b149b6686c446871" userId="9" frames="9668736"/> </records> </composition> </rss>
Output for 4.3.2 - 4.4.9
Warning: Wrong parameter count for str_replace() in /in/g2sP4 on line 25 Warning: Wrong parameter count for str_replace() in /in/g2sP4 on line 25 Warning: Wrong parameter count for str_replace() in /in/g2sP4 on line 25