3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $basepath = '/home/robert/www/prod/htdocs'; $fullpath = '/home/robert/www/prod/htdocs/intra/announcements/index.php'; $b = explode('/',$basepath); $f = explode('/',$fullpath); $z = true; $max = 30; $i=0; while($z){ $bp = array_shift($b); $fp = array_shift($f); $z = $bp == $fp; $i++; if($i==$max) break; } array_unshift($f,$fp); $sfp = implode('/',$f); echo $sfp;
based on 5VYDF
Output for 4.3.0 - 7.2.0
intra/announcements/index.php