3v4l.org

run code in 300+ PHP versions simultaneously
<?php class php { /** * str_replace() from the end of a string that can also be limited e.g. replace only the last instance of '</div>' with '' * * @param string $find * @param string $replace * @param string $subject * @param int $replacement_limit | -1 to replace all references * * @return string */ public static function str_replace($find, $replace, $subject, $replacement_limit = -1) { $find_pattern = str_replace('/', '\/', $find); return preg_replace('/' . $find_pattern . '/', $replace, $subject, $replacement_limit); } /** * str_replace() from the end of a string that can also be limited e.g. replace only the last instance of '</div>' with '' * * @param string $find * @param string $replace * @param string $subject * @param int $replacement_limit | -1 to replace all references * * @return string */ public static function str_rreplace($find, $replace, $subject, $replacement_limit = -1) { return strrev( self::str_replace(strrev($find), strrev($replace), strrev($subject), $replacement_limit) ); } } $find = '$'; $replace = 'dollar'; $subject = 'This is a $ symbol. I like making $s.'; echo php::str_replace($find, $replace, $subject);
Output for git.master, git.master_jit, rfc.property-hooks
This is a $ symbol. I like making $s.dollar

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:
64.89 ms | 401 KiB | 8 Q