3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $base = '/some/dir'; $path = 'scr/bar'; $protect = array('a','foo','bob'); foreach($protect as $needle) { echo "Checking for $needle in $path<br/>"; if( strpos($path,$needle) !==FALSE ) { echo "path contains the needle"; if( strcmp( $path, $needle ) > 0 ) { echo "The path is a subfolder inside the needle"; } else { echo "The path isn't a subfolder inside the needle"; } } else { echo "The path doesn't contain the needle"; } echo "<br/><br/>"; } echo "Check completed"; ?>
Output for 4.3.0 - 7.1.0
Checking for a in scr/bar<br/>path contains the needleThe path is a subfolder inside the needle<br/><br/>Checking for foo in scr/bar<br/>The path doesn't contain the needle<br/><br/>Checking for bob in scr/bar<br/>The path doesn't contain the needle<br/><br/>Check completed