如何使用PHP从不同目录中获取文件

I understand in HTML, you can use ../../../ to include content which is included in other folders.

I have this PHP code and I'm wondering how can I use ../../../ before header.php?

<?php
ob_start();
include("../../../header.php");
$buffer=ob_get_contents();
ob_end_clean();
$buffer=str_replace("%TITLE%","Homepage",$buffer);
echo $buffer;
?>

you can use chdir() php function and getcwd(). im suggest you use constant as source path location..

try this:

<?php
ob_start();
chdir("../../../");
$cwd =  rtrim(str_replace("\\", "/", getcwd()), '/').'/';
include($cwd."header.php");
$buffer=ob_get_contents();
ob_end_clean();
$buffer=str_replace("%TITLE%","Homepage",$buffer);
echo $buffer;
?>