开发者

file_get_contents() misuse

开发者 https://www.devze.com 2023-02-10 09:39 出处:网络
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

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? 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');
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号