如何彻底清洁元素?

时间:2011-08-17 01:39:48

标签: php html-parsing simple-html-dom

我使用simplehtmldom.sourceforge.net

我需要明确元素$e <font size="2"><b>Listen to INT_routine on the January 15th, 2007 Urban-D Radio Podcast!</b></font>

我使用函数:$e->clear()元素删除,但留下</font>

如何彻底清洁元素?

1 个答案:

答案 0 :(得分:0)

我从来没有使用过这个库,但仔细观察它。看看这是否有效..

echo str_get_html('<font size="2"><b>Listen to INT_routine on the January 15th, 2007 Urban-D Radio Podcast!</b></font>')->plaintext;

或者这个。 。

$tagtext = (string)"<font size="2"><b>Listen to INT_routine on the January 15th, 2007 Urban-D Radio Podcast!</b></font>";
var_dump(str_get_html($tagtext)->plaintext);

修改:

// Example 

$html = str_get_html("<div>foo <b>bar</b></div>");  
$e = $html->find("div", 0); 

echo $e->tag; // Returns: " div" 

echo $e->outertext; // Returns: " <div>foo <b>bar</b></div>" 

echo $e->innertext; // Returns: " foo <b>bar</b>"

echo $e->plaintext; // Returns: " foo bar"