3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string = "[vc_tab [vc_tab [vc_tab [vc_tab [vc_tab [vc_tab"; $active = 3; $needle = "[vc_tab"; $replace = '[vc_tab active="true"'; if( substr_count( $string, $needle) < $active) { throw new Exception("There aren't enough needles in the string to do this replacement"); } $count = 0; $index = 0; while( $count++ < $active) { $index = strpos( $string, $needle, $index) + ; } $result = substr( $string, $index - strlen( $needle)) . $replace . substr( $string, $index); echo "Index: ", $index, " ", $result;
Output for 5.3.0 - 5.3.27, 5.4.0 - 5.4.18, 5.5.0 - 5.5.1
Parse error: syntax error, unexpected ';' in /in/4kM9W on line 14
Process exited with code 255.

preferences:
169.62 ms | 1395 KiB | 56 Q