3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function mystr_replace($needle,$replace,$haystack){ $args = func_get_args(); $count=null; if(isset($args[3])){ $count &= $args[3]; } var_dump($args); if(is_null($count)) { return "3:".str_replace($needle,$replace,$haystack); } else { return "4:".str_replace($needle,$replace,$haystack,$count); } } echo mystr_replace("frop","frml","fropfrop")."\n"; echo mystr_replace("frop","frml","fropfrop",1)."\n";
based on GF93C
Output for 4.3.0 - 4.3.1, 5.0.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
array(3) { [0]=> string(4) "frop" [1]=> string(4) "frml" [2]=> string(8) "fropfrop" } 3:frmlfrml array(4) { [0]=> string(4) "frop" [1]=> string(4) "frml" [2]=> string(8) "fropfrop" [3]=> int(1) } 4:frmlfrml
Output for 4.3.2 - 4.4.9
array(3) { [0]=> string(4) "frop" [1]=> string(4) "frml" [2]=> string(8) "fropfrop" } 3:frmlfrml array(4) { [0]=> string(4) "frop" [1]=> string(4) "frml" [2]=> string(8) "fropfrop" [3]=> int(1) } Warning: Wrong parameter count for str_replace() in /in/R9isk on line 12 4: