3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str1 = ["AD-2018-34567-234","10256","1234567890-rfwet043-123455-cd1234-sdf"]; $str2 = ["cd 34567","cd 10256","4edgs-cd12340e-3ed"]; foreach($str1 as $key => $str){ $find = $str2[$key]; $l = strlen($find); $match = false; for($i=0; $i<=($l-5);$i++){ // loop the find string //echo $str . " " . substr($find,$i, 5) . "\n"; // debug if(strpos($str, substr($find,$i, 5)) !== false) { // take five characters at the time and stros them $match = true; break; } } if($match){ echo "match\n"; }else{ echo "no match\n"; } }
Output for 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.27, 8.4.1 - 8.4.14
match match match

preferences:
156.19 ms | 408 KiB | 5 Q