Search code examples
phprelative-pathabsolute-path

Get absolute path of a relative path of a XML file


Is it possible to guess the absolute path of a relative path that I have specified for loading a XML file? This is my coding:

$strXML = __DIR__ . "/../xml/file.xml";
$xmlFile = simplexml_load_file($strXML);

$strPath = fullPathFunction($xmlFile);  //Desired function

Solution

  • You can use realpath function:

    $strXML = "../xml/file.xml";
    $xmlFile = simplexml_load_file($strXML);
    
    $strPath = realpath($strXML);
    

    This example works for me