So I am not exactly sure why my code doesn't work, but here is the error I get:
Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "../../setting.xml" in /home1/sk8ermid/public_html/MVP/themes/SDS-2013/home.php on line 3
Here is the code I use:
<?php
$settings = simplexml_load_file('../../setting.xml');
$site_title = $settings->title;
?>
I am trying to go up two directories where the "settings.xml" file is at. Am I am doing this the right way or is there another way to do this?
Try this
$settings = simplexml_load_file(__DIR__ . '/../../setting.xml');
Always keep in mine that .
(the CWD) is the directory of the PHP script at the root of any include
/ require
tree and only then if your configured include_path
actually includes .
(which it does by default though this can be changed in code).
If your home.php
script is included by another script in a different directory, .
is relative to that other script.
Using __DIR__
makes sure you're always starting at the parent directory of the current script.