3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $search = "phpversion()|apple"; echo '<br/>'; $pos = strpos($search, 'apple'); if($pos !== false){ echo $pos . '<br/>'; }else{ echo 'false' . '<br/>'; } echo 'search ' . $search . '<br/>'; echo 'pattern = ' . "/".$search."/"; echo '<br/>'; echo 'replacement = ' . $search . "'<'img src='".$search.".png''/>'"; echo '<br/>'; echo 'preg_replace = ' . preg_replace("/".$search."/", $search." <img src='".$search.".png'>", "apple"); echo '<br/>'; if (strpos($search, 'apple') !== false){ echo preg_replace("/".$search."/", $search." <img src='".$search.".png'>", "apple"); }elseif (strpos($search, 'orange') !== false){ echo preg_replace("/".$search."/", $search." <img src='".$search.".png'>", "orange"); }elseif (strpos($search, 'banana') !== false){ echo preg_replace("/".$search."/", $search." <img src='".$search.".png'>", "banana"); }elseif (strpos($search, 'k') !== false){ echo preg_replace("/".$search."/", $search, "kiwi"); }else{ echo "Please search for apple, orange, banana, or kiwi."; } ?>
based on KNIRU
Output for 4.3.0 - 7.1.0
<br/>13<br/>search phpversion()|apple<br/>pattern = /phpversion()|apple/<br/>replacement = phpversion()|apple'<'img src='phpversion()|apple.png''/>'<br/>preg_replace = phpversion()|apple <img src='phpversion()|apple.png'><br/>phpversion()|apple <img src='phpversion()|apple.png'>