Assuming this works properly for telling if a substring is in a string, is there a more concise way to do this?
if(is_int(strpos($haystack, $needle))){
...
}
I wouldn't do it that way. Just make a strict comparison to FALSE
.
$found = strpos($haystack, $needle) !== FALSE;
Not really. It really comes down to your preference for which one is the clearest way to express what you're doing. Some alternatives:
if( strpos( $h, $n ) !== FALSE ){
// stuff
}
if( strpos( $h, $n ) > -1 ){
// stuff
}
The most common approach is probably to use the strict FALSE
comparison, so if you're working on an open-source project or have a lot of other people using your code, consider that option.