3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function is_str_contain($string, $keyword){ if(empty($string) || empty($keyword)) return false; $keyword_first_char = $keyword[0]; $keyword_length = strlen($keyword); $string_length = strlen($string); if( $string_length < $keyword_length ) return false; if( $string_length == $keyword_length ){ if($string == $keyword) return true; else return false; } if($keyword_length > 1){ for( $i=0; $i < $string_length; $i++){ //check if keyword's first char == string's first char if( $keyword_first_char == $string[$i] ){ $match = 1; for($j = 1; $j < $keyword_length; $j++){ if( ($i+$j < $string_length) && $keyword[$j] == $string[$i+$j] ){ $match++; } } if($match == $keyword_length){ return true; } } } } if($keyword_length == 1){ for( $i=0; $i < $string_length; $i++){ //check if keyword's first char == string's first char if( $keyword_first_char == $string[$i] ){ return true; } } } return false; } var_dump(is_str_contain("test", "t")); //true var_dump(is_str_contain("test", "")); //false var_dump(is_str_contain("test", "test")); //true var_dump(is_str_contain("test", "testa")); //flase var_dump(is_str_contain("a----z", "a")); //true var_dump(is_str_contain("a----z", "z")); //true
Output for 4.3.0 - 5.0.5, 5.1.1 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
bool(true) bool(false) bool(true) bool(false) bool(true) bool(true)
Output for 5.1.0
Fatal error: fatal flex scanner internal error--end of buffer missed in /in/643Dc on line 55
Process exited with code 255.