I have simplexml_load_file
instruction placed withing included PHP file. But this instruction works depending on where I include this file from. Why? Is it possible to make relative file path be interpreted relatively to the file instruction placed in?
You can always access the current file's full path with the magic __FILE__ constant, so you can write your simplexml_load_file() call like this:
<?php
simplexml_load_file(dirname(__FILE__).'/file.xml');
Since PHP 5.3, there have been a new __DIR__
introduced, you can use it in place of the dirname(__FILE__)
like this:
<?php
simplexml_load_file(__DIR__).'/file.xml');