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'));

preferences:
21.61 ms | 476 KiB | 4 Q