3v4l.org

run code in 300+ PHP versions simultaneously
<? $data = "The cat likes to sit on the fence. He also likes to climb the tree."; $find ="/the/"; $replace ="a"; //1. replace single word Echo "$data <br>"; Echo preg_replace ($find, $replace, $data); //create arrays $find2 = array ('/the/', '/cat/'); $replace2 = array ('a', 'dog'); //2. replace with array values Echo preg_replace ($find2, $replace2, $data); //3. Replace just once Echo preg_replace ($find2, $replace2, $data, 1); //4. Keep a count of replacements $count = 0; Echo preg_replace ($find2, $replace2, $data, -1, $count); Echo "<br>You have made $count replacements"; ?>
Output for git.master, git.master_jit, rfc.property-hooks
<? $data = "The cat likes to sit on the fence. He also likes to climb the tree."; $find ="/the/"; $replace ="a"; //1. replace single word Echo "$data <br>"; Echo preg_replace ($find, $replace, $data); //create arrays $find2 = array ('/the/', '/cat/'); $replace2 = array ('a', 'dog'); //2. replace with array values Echo preg_replace ($find2, $replace2, $data); //3. Replace just once Echo preg_replace ($find2, $replace2, $data, 1); //4. Keep a count of replacements $count = 0; Echo preg_replace ($find2, $replace2, $data, -1, $count); Echo "<br>You have made $count replacements"; ?>

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:
55.3 ms | 402 KiB | 8 Q