Jake
Jake

Reputation: 913

PHP Snippet Issue

I have a PHP file (myFile.php) that parses XML, and assigns the data I need to a variable ($myVar). I need to echo this variable on an HTML page. I’ve tried adding <?php include ‘/myFile.php’; echo $myVar; ?> to the HTML file to no avail, however if I call the script itself (http://localhost/myFile.php) and add echo $myVar; to the end of the file the data is displayed as expected.

Am I missing something simple? I’m running PHP7 on a Linux Apache server - is there a setting somewhere that I need to change? I’ve used this syntax in the past without issue.

Thank you for the second set of eyes!

Upvotes: 0

Views: 31

Answers (1)

user7744592
user7744592

Reputation:

Try the following:

<?php
    include $_SERVER['DOCUMENT_ROOT'] . '/myFile.php';
    echo $myVar;
?>

Upvotes: 1

Related Questions