3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $base = '/some/dir'; $path = '/foo/bar'; $protect = array('/bar','/foo','/bob'); foreach($protect as $needle) { echo "Checking for $needle in $path:\n"; if( strpos($path,$needle) !==FALSE ) { echo "path contains the needle"; if( strcmp( $needle, $path ) > 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 "\n\n"; } echo "Check completed"; ?>
Output for 4.3.0 - 5.6.28, hhvm-3.12.0, 7.0.0 - 7.1.0
Checking for /bar in /foo/bar: path contains the needleThe path isn't a subfolder inside the needle Checking for /foo in /foo/bar: path contains the needleThe path isn't a subfolder inside the needle Checking for /bob in /foo/bar: The path doesn't contain the needle Check completed
Output for hhvm-3.10.0

Process exited with code 153.