脚本宝典收集整理的这篇文章主要介绍了simplehtmldom Doc api帮助文档,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
API Reference
Hel
PEr functions
object str_get_ht
ML ( string $content ) Creates a DOM object
From a string.
object file_get_html ( string $filen
ame ) Creates a DOM object f
rom a file or a URL. DOM methods &
PRoperties stringpl
aintext Returns the contents extracted from HTML.
vo
IDClear () Clean up memory.
voidload ( string $content ) Load contents from a string.
stringsave ( [string $filename] ) Dumps the internal DOM tree back into a string. If the $filename is set,result string will save to file.
voidload_file ( string $filename ) Load contents from a from a file or a URL.
voidset_callback ( string $function_name ) Set a callback function.
mixe
DFind ( string $selector [,int $index] ) Find elements by the CSS selector. Returns the Nth element object if index is set,otherwise return an array of object. Element methods & properties string[attribute] Read or wr
ITe element's attribure value.
stringtag Read or write the tag name of element.
stringoutertext Read or write the outer HTML text of element.
strin
ginnertext Read or write the inner HTML text of element.
stringplaintext Read or write the plain text of element.
mixedfind ( string $selector [,int $index] ) Find children by the CSS selector. Returns the Nth element object if index is set,otherwise,return an array of object. DOM traversing mixed$e->children ( [int $index] ) Returns the Nth child object if index is set,otherwise return an array of children.
element$e->parent () Returns the parent of element.
element$e->
First_child () Returns the first child of element,or null if not found.
element$e->last_child () Returns the last child of element,or null if not found.
element$e->next_sibling () Returns the next sibling of element,or null if not found.
element$e->p
rev_sibling () Returns the prev
IoUs sibling of element,or null if not found.
Camel n
aming convertions You can also call methods with W3C STANDARD camel naming convertions.
string$e->getAttribute ( $name ) string$e->attribute
void$e->
setattribute ( $name,$value ) void$value = $e->attribute
bool$e->hasAttribute ( $name ) boolisset($e->attribute)
void$e->removeAttribute ( $name ) void$e->attribute = null
element$e->getElementById ( $id ) mixed$e->find ( "
#$id",0 )
mixed$e->getElementsById ( $id [,$index] ) mixed$e->find ( "#$id" [,int $index] )
element$e->getElementByTagName ($name ) mixed$e->find ( $name,0 )
mixed$e->
getelementsbytagname ( $name [,$index] ) mixed$e->find ( $name [,int $index] )
element$e->parentNode () element$e->parent ()
mixed$e->childNodes ( [$index] ) mixed$e->children ( [int $index] )
element$e->firstChild () element$e->first_child ()
element$e->lastChild () element$e->last_child ()
element$e->nextSibling () element$e->next_sibling ()
element$e->prev
IoUsSibling () element$e->prev_sibling () // Create a DOM object from a string
$html = str_get_html('Hello!'); // Create a DOM object from a URL
$html = file_get_html('http://www.
GOOGLE.COM/'); // Create a DOM object from a HTML file
$html = file_get_html('
test.htm'); // Create a DOM object
$html = new
simple_html_dom(); // Load HTML from a string
$html->load('Hello!'); // Load HTML from a URL
$html->load_file('http://www.google.com/'); // Load HTML from a HTML file
$html->load_file('test.htm');
// Find all anchors,returns a array of element objects
$ret = $html->find('a'); // Find (N)thanchor,returns element object or null if not found(zero based)
$ret = $html->find('a',0); // Find all
which attribute id=foo
$ret = $html->find('div[id=foo]'); // Find all
with the id attribute
$ret = $html->find('div[id]'); // Find all element has attribute id
$ret = $html->find('[id]');
// Find all element which id=foo
$ret = $html->find('#foo'); // Find all element which class=foo
$ret = $html->find('.foo'); // Find all anchors and images
$ret = $html->find('a,
img'); // Find all anchors and images with the "title" attribute
$ret = $html->find('a[title],img[title]'); // Find all
in
$es = $html->find('ul li'); // Find Nested tags
$es = $html->find('div div div'); // Find all
| $es = $html->find('table.hello td'); // Find all td tags with attribite align=
center in table tags
$es = $html->find(''table td[align=center]'); // Find all
- in
foreach($html->find('ul') as $ul)
{
foreach($ul->find('li') as $li)
{
// do something...
}
} // Find first - in first
$e = $html->find('ul',0)->find('li',0); Supports these operators in attribute selectors:
[attribute] Matches elements that have the specified attribute.
[attribute=value] Matches elements that have the specified attribute with a certain value.
[attribute!=value] Matches elements that don't have the specified attribute with a certain value.
[attribute^=value] Matches elements that have the specified attribute and it starts with a certain value.
[attribute$=value] Matches elements that have the specified attribute and it ends with a certain value.
[attribute*=value] Matches elements that have the specified attribute and it contains a certain value. // Find all text blocks
$es = $html->find('text'); // Find all comment () blocks
$es = $html->find('comment'); // 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,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!'; // Example
$html = str_get_html("foo bar
");
$e = $html->find("div",0); echo $e->tag; // Returns: " div"
echo $e->outertext; // Returns: " foo bar
"
echo $e->innertext; // Returns: " foo bar"
echo $e->plaintext; // Returns: " foo bar"
$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. // Extract contents from HTML
echo $html->plaintext; // Wrap a element
$e->outertext = 'outertext . '
'; // Remove a element,set it's outertext as an empty string
$e->outertext = ''; // Append a element
$e->outertext = $e->outertext . '
foo
'; // Insert a element
$e->outertext = '
foo
' . $e->outertext; // If you are not so familiar with HTML DOM,check this link to learn more... // Example
echo $html->find("#div1",0)->children(1)->children(1)->children(2)->id;
// or
echo $html->getElementById("div1")->childNodes(1)->childNodes(1)->childNodes(2)->getAttribute('id');
You can also call methods with Camel naming convertions. mixed$e->children ( [int $index] ) Returns the Nth child object if index is set,or null if not found. // Dumps the internal DOM tree back into string
$str = $html; // Print it!
echo $html; // Dumps the internal DOM tree back into string
$str = $html->save(); // Dumps the internal DOM tree back into a file
$html->save('result.htm'); // Write a function with parameter "$element"
function my_callback($element) {
// Hide all
tags
if ($element->tag=='b')
$element->outertext = '';
} // Register the callback function with it's function name
$html->set_callback('my_callback'); // Callback function will be invoked while dumping
echo $html;
本图文内容来
源于
网友网络收集整理提供,作为学习参考使用,版权属于原作者。
php中有以下五种方法来检测变量
是否为空,那么这五种方法之间有什么区别呢?下面我们就来一起看看吧。1、isset功能:
判断变量是否被初始化说明:它并不会判断变量是否为空,可以用来判断数组中元素是否被定义过。
字符串函数
strlen:获取字符串的长度,获取的是字符串的字节长度 字符:一个完整的符号,a,中 字节:由8位组成 一个字符最少等于一个字节:ASCII码,a,b,通常英文字符都是占用一个字节 中文在gbk
或者gb2312编码里,占用两个字节 中文在utf-8里最少占用3个字节,有可能是4个字节 s
ubstr:截取字符串,以字节为单位截取 string sub...
数据的操作无外乎就是对数据的增删改查增加数据基本方式:insert into 表名 [(字段列表)] values (值列表);主键冲突:在
插入数据的时候,主
键值已经存在了,但是要求是必须使用该主键字段 实现目标:如果该主键不存在那么就增加记录,如果存在,就修改部分字段的值1.使用主键冲突方式语法:insert into 表名 values(值列表) on dup...
范式:Normal Format规定的一种设计方式范式特点:范式有很多,从低级到高级有六级左右,低级往高级一级比一级要求严格。关系型
数据库通常设计只需要满足其中一
半,满足第三范式即可。满足第三范式必须先满足第二范式,第二范式又必须先满足第一范式。第一范式:1NF数据表的设计的字段中,每个字段都不能再分,每个字段都必须是最小的不可分割的单位(原子性) 讲师代课表 要知...
在字段类型之后,用于对当前字段进行一
系列的约束的内容(限制内容的情况) 字段属性:null/not null,
Primary key,auto_increment,
unique key,comment,defaultnull表示字段的值可以为空(在进行数据插入的时候,该字段可以不给数据),not null表示不能为空,必须要给定值(不能是null)default默...
MySQL中也分为三
大数据类型:数值型,字符型,
时间日期型 数值型数值型分为整数型和小数型(包含小数部分的数据类型)
整型my
SQL中光整数型数据类型就有五种:tinyint,smallint,mediumint,int,
Bigint tinyint:迷你整型,占用1个字节保存数据,能够表示256个数值 smallint:小整型,占用2个字节保存数据,能够表示6...
校对集就是数据库数据进行比较的时候所采用的比较方式。 A
=======&am
p;amp;gt; 01000001 =======> 65 a =======> 01100001 ========> 97校对集有三种比较方式 _bin:使用二进制进行比较(区分大小写) _ci:(case insensitive),大小写不敏感,不区分大小写(将某个字符转变成...
1.mytable1存储的数据是utf8字符集(在创建表的时候,指定了表的数据存储字符集为utf8)2.cmd控制台只能是gbk格式的数据:说明cmd下只能输入和显示gbk格式的数据3.set
names gbk的功能 客户端与服务端进行不同编码的通信的原理
了解数据库的字符集 查看数据库支持
哪些字符集?show character set; mysql支持39种字...
脚本宝典总结
以上是脚本宝典为你收集整理的simplehtmldom Doc api帮助文档全部内容,希望文章能够帮你解决simplehtmldom Doc api帮助文档所遇到的问题。
如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。