开发者

Change a HTML attribute: xml:lang

Here's my html code:

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

I want to change the attribute of xml:lang="en" into xml:lang="Foobar" and the next lang="en" into xml:lang="Foobar"

Does this parser work? Simple HTML DOM Parser As i read the documentation, it should goes like this:

$html = file_get_html('D:\xampp\htdocs\hmtl\index.html'); 
$value = $html->lang;
$html->href = 'Foobar';

But, it's not working. What am i missing here? Ple开发者_JS百科ase help.


file_get_contents() does not generate an HTML DOM. It simply reads the file as plain text.

Therefore, before you can use $html->lang or $html->href, you need to convert the plain text into a DOM object structure. As described in the link you provided, you would need to use the function str_get_html(), between file_get_contents() and trying to use the DOM object.

Alternatively, the same page also lists an entirely object-oriented way to do it:

$html = new simple_html_dom();
$html->load_file('test.htm');

...where you would obviously replace test.htm with your file path.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜