Dom class is Miss

Source: Internet
Author: User
Tags ldap

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.