3v4l.org

run code in 500+ PHP versions simultaneously
<?php $string = 'text a[link1], a[link2] a[link3] text text text a[link4] text a[link5] text'; $styleCounter = 0; echo preg_replace_callback( '/((?<=]))?+(,? ?)a\[([^][]*)]/', function ($m) use(&$styleCounter) { if ($m[1] === null) { ++$styleCounter; } return "{$m[2]}<a href=\"{$m[3]}\" class=\"style{$styleCounter}\">{$m[3]}</a>"; }, $string, -1, $count, PREG_UNMATCHED_AS_NULL ); /*<a href="link1" class="style1">link1</a><a href="link2" class="style1">link2</a><a href="link3" class="style1">link3</a> text text text <a href="link4" class="style2">link4</a> text <a href="link5" class="style2">link5</a> text*/
Output for rfc.property-hooks, git.master, git.master_jit
text <a href="link1" class="style1">link1</a>, <a href="link2" class="style1">link2</a> <a href="link3" class="style1">link3</a> text text text <a href="link4" class="style2">link4</a> text <a href="link5" class="style3">link5</a> text

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:
52.08 ms | 1300 KiB | 4 Q