0

This I cant seem to figure out. In a nutshell I have a webpage that will change depending on $_GET variables set. When building the webpage there are 2 menus to choose from. These menus are stored in html files.

Here is the line that is reading that file.

$template->set('menu',file_get_contents('../gamefiles/site_menu.html'));

Here is the function that the line is running.

function set($div,$data)
{
    $result = $this->xpath->query("//div[@id = '".$div."']");
    $node = $result->item(0);
    $node->nodeValue = $data;
    $this->dom->saveHTML();
}

Here is what is in the menu file.

<a href=''><div>Home</div></a><br />
<a href=''><div>Documentation</div></a><br />
<a href=''><div>Support</div></a><br />
<a href=''><div>Affiliates</div></a><br />
<a href=''><div>Sign up!</div></a><br />

and here is where my problem is... for some reason its returning

&lt;a href=''&gt;&lt;div&gt;Home&lt;/div&gt;&lt;/a&gt;&lt;br /&gt;
&lt;a href=''&gt;&lt;div&gt;Documentation&lt;/div&gt;&lt;/a&gt;&lt;br /&gt;
&lt;a href=''&gt;&lt;div&gt;Support&lt;/div&gt;&lt;/a&gt;&lt;br /&gt;
&lt;a href=''&gt;&lt;div&gt;Affiliates&lt;/div&gt;&lt;/a&gt;&lt;br /&gt;
&lt;a href=''&gt;&lt;div&gt;Sign up!&lt;/div&gt;&lt;/a&gt;&lt;br /&gt;

file_get_contents() when used alone returns the correct value which leads me to believe the DOMXPath function is doing something to it. Im pretty stumped.

any ideas? thanks in advance

EDIT

adding construct method that creates DOMDoc

function __CONSTRUCT($template)
{
    $this->dom = new DomDocument();
    $this->dom->loadHTML(file_get_contents($this->template_dir.$template));
    $this->xpath = new DomXPath($this->dom);
}
steve
  • 290
  • 1
  • 11

1 Answers1

0

Not sure what charset you sending in the header, but I've run into something similar before and that was the issue. Try using:

header('Content-Type: text/html; charset=UTF-8');
Chris Schmitz
  • 8,097
  • 6
  • 31
  • 41