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 $needle in path $path:\n"; $sp = strpos($path,$needle); echo "Strpos result: $sp\n"; if( $sp !==FALSE ) { echo "Path contains the needle\n"; $s=strcmp( $needle, $path ); echo "Strcmp result: $s\n"; if( $s > 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, 7.0.0 - 7.1.0
Checking for needle /bar in path /foo/bar: Strpos result: 4 Path contains the needle Strcmp result: -1024 The path isn't a subfolder inside the needle Checking for needle /foo in path /foo/bar: Strpos result: 0 Path contains the needle Strcmp result: -4 The path isn't a subfolder inside the needle Checking for needle /bob in path /foo/bar: Strpos result: The path doesn't contain the needle Check completed
Output for hhvm-3.10.0 - 3.12.0
Checking for needle /bar in path /foo/bar: Strpos result: 4 Path contains the needle Strcmp result: -1 The path isn't a subfolder inside the needle Checking for needle /foo in path /foo/bar: Strpos result: 0 Path contains the needle Strcmp result: -4 The path isn't a subfolder inside the needle Checking for needle /bob in path /foo/bar: Strpos result: The path doesn't contain the needle Check completed