You just need to create an offset bypass to how far you want the backwards reading to go. So, we use getcwd()
to get the path and explode (split into array) to fetch the data between $root
and the ending of the path.
function getRoot($root = "public_html") {
return explode($root, getcwd())[0].$root."/";
}