3v4l.org

run code in 300+ PHP versions simultaneously
<?php $bads = array('+11','- 68','[img','$cool', '# hash'); // disallowed full 'words'; if one of them appears in string, the function should return true $s= 'This is test to show if or $cool works but it does not'; //another example to test: $s= 'This - 68 is # hash not'; if(contains($s,$bads)) { echo 'Contains! '; } #### FUNCTION ### function contains($str, $bads) { //var_dump($bads); $b = "/"; foreach($bads as $a) { if(substr($a,0,1) == "$"){ $b .= preg_quote($a,'/'). "|"; }else{ $b .= "\b" . preg_quote($a,'/'). "\b|"; } } $b = substr($b, 0,-1) ."/"; echo $b; if(preg_match($b,$str, $m)){ var_dump($m); return true; } return false; }
Output for git.master, git.master_jit, rfc.property-hooks
/\b\+11\b|\b\- 68\b|\b\[img\b|\$cool|\b\# hash\b/array(1) { [0]=> string(5) "$cool" } Contains!

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:
29.03 ms | 405 KiB | 5 Q