- substr: documentation ( source)
<?php
$chapter_full_path = "/test/eeee/last/";
$chapter_path_name = "/last/";
$chapter_path_name_length=strlen($chapter_path_name);
$oldParentFullPathLength = strlen($chapter_full_path) - $chapter_path_name_length;
$oldParentFullPath=substr($chapter_full_path,0,$oldParentFullPathLength);
echo $oldParentFullPath;