file_get_contents() misuse
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
<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 />
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? thank开发者_如何学运维s 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);
}
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');
精彩评论