3v4l.org

run code in 500+ PHP versions simultaneously
<?php $string = "An elephant is an elephant"; print str_replace('ph', 'php', $string); print PHP_EOL; $closure = function() { static $count = 0; ++$count; return $count === 2 ? 'php' : 'ph'; }; print preg_replace_callback('/ph/', $closure, $string); print PHP_EOL; $pos1 = strpos($string, 'ph'); $pos2 = strpos($string, 'ph', $pos1 + 3); print substr_replace($string, 'php', $pos2, strlen('ph'));
Output for 8.2.34, 8.3.0 - 8.3.35, 8.4.1 - 8.4.26, 8.5.0 - 8.5.11
An elephpant is an elephpant An elephant is an elephpant An elephant is an elephpant

preferences:
26.88 ms | 1151 KiB | 7 Q