Dom functions is not installed by default in PhP5 on centos5.2,
Use the following test cases:
> 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 'domaindocument' not found in/home/DOM. php on line 3 is displayed.
That means PHP-dom Is Not Installed
It can be installed through 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
(2/5): php-5.1.6-23.el5. I 100% | =========================| 1.2 MB
(3/5): php-xml-5.1.6-23.e 100% | =========================| 95 KB
(4/5): php-ldap-5.1.6-23. 100% | = 35 KB
(5/5): php-cli-5.1.6-23.e 100% | =========================| 2.1 MB
OK. Check the PHP running status after installation.
> PHP Dom. php
PHP hacks-Jack herrington-O 'Reilly
Podcasting hacks-Jack herrington-O 'Reilly
Similarly, you can install the GD library like this.
> Yum install PHP-Gd
Note: To apply the application to the Web, you need to restart Apache
> Service httpd restart