|
centos5.2上的php5默认是没有安装DOM Functions的,
使用测试用例如下:
>vi dom.php
<?php
$doc = new DOMDocument();
$doc->load('books.xml');
$books = $doc->getElementsByTagName("book");
foreach($books as $book)
{
$authors = $book->getElementsByTagName("author");
$author = $authors->item(0)->nodeValue;
$publishers = $book->getElementsByTagName("publisher");
$publisher = $publishers->item(0)->nodeValue;
$titles = $book->getElementsByTagName("title");
$title = $titles->item(0)->nodeValue;
echo "$title-$author-$publisher\n";
}
>vi books.xml
<books>
<book>
<author>Jack Herrington</author>
<title>PHP Hacks</title>
<publisher>O'Reilly</publisher>
</book>
<book>
<author>Jack Herrington</author>
<title>Podcasting Hacks</title>
<publisher>O'Reilly</publisher>
</book>
</books>
>php dom.php
此时显示PHP Fatal error: Class 'DOMDocument' not found in /home/dom.php on line 3
那意味着php-dom没有被安装
可以通过yum可以安装;
>yum install php-dom
=============================================================================
Package Arch Version Repository Size
=============================================================================
Installing:
php-xml i386 5.1.6-23.el5 base 95 k
Updating:
php-common i386 5.1.6-23.el5 base 154 k
Updating for dependencies:
php i386 5.1.6-23.el5 base 1.2 M
php-cli i386 5.1.6-23.el5 base 2.1 M
php-ldap i386 5.1.6-23.el5 base 35 k
Transaction Summary
=============================================================================
Install 1 Package(s)
Update 4 Package(s)
Remove 0 Package(s)
Total download size: 3.5 M
Is this ok [y/N]: y
Downloading Packages:
(1/5): php-common-5.1.6-2 100% |=========================| 154 kB 00:00
(2/5): php-5.1.6-23.el5.i 100% |=========================| 1.2 MB 00:05
(3/5): php-xml-5.1.6-23.e 100% |=========================| 95 kB 00:00
(4/5): php-ldap-5.1.6-23. 100% |=========================| 35 kB 00:00
(5/5): php-cli-5.1.6-23.e 100% |=========================| 2.1 MB 00:09
OK,安装完成后再看看php的运行情况
>php dom.php
PHP Hacks-Jack Herrington-O'Reilly
Podcasting Hacks-Jack Herrington-O'Reilly
同样,对于gd库也可以这样安装
>yum install php-gd
注意,要应用到web,需要重新启动下apache
>service httpd restart |
|