码迷,mamicode.com
首页 > Web开发 > 详细

simple_html_dom(2)

时间:2014-10-14 21:48:19      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:color   ar   strong   sp   div   on   html   amp   ad   

How to access the HTML element‘s attributes?

// Get a attribute ( If the attribute is non-value attribute (eg. checked, selected...), it will returns true or false)
$value = $e->href;

// Set a attribute(If the attribute is non-value attribute (eg. checked, selected...), set it‘s value as true or false)
$e->href = ‘my link‘;

// Remove a attribute, set it‘s value as null! 
$e->href = null;

// Determine whether a attribute exist? 
if(isset($e->href)) 
        echo ‘href exist!‘;

// Extract contents from HTML 
echo $html->plaintext;

// Wrap a element
$e->outertext = ‘<div class="wrap">‘ . $e->outertext . ‘<div>‘;

// Remove a element, set it‘s outertext as an empty string 
$e->outertext = ‘‘;

// Append a element
$e->outertext = $e->outertext . ‘<div>foo<div>‘;

// Insert a element
$e->outertext = ‘<div>foo<div>‘ . $e->outertext;

// 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"

Attribute NameUsage
$e->tag Read or write the tag name of element.
$e->outertext Read or write the outer HTML text of element.
$e->innertext Read or write the inner HTML text of element.
$e->plaintext Read or write the plain text of element.

simple_html_dom(2)

标签:color   ar   strong   sp   div   on   html   amp   ad   

原文地址:http://www.cnblogs.com/goAhead-hust/p/4025032.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!