This is my first php program!



Download 6,9 Mb.
Pdf ko'rish
bet66/69
Sana26.02.2022
Hajmi6,9 Mb.
#471647
1   ...   61   62   63   64   65   66   67   68   69
Bog'liq
PHP

276
|
Chapter 11: XML
function BookList ($filename) {
$this->parser = xml_parser_create( );
xml_set_object($this->parser, &$this);
xml_set_element_handler($this->parser, 'start_element', 'end_element');
xml_set_character_data_handler($this->parser, 'cdata');
// 1 = single field, 2 = array field, 3 = record container
$this->field_type = array('title' => 1,
'author' => 2,
'isbn' => 1,
'comment' => 1);
$this->ends_record = array('book' => true);
$x = join("", file($filename));
xml_parse($this->parser, $x);
xml_parser_free($this->parser);
}
function start_element ($p, $element, &$attributes) {
$element = strtolower($element);
if ($this->field_type[$element] != 0) {
$this->current_field = $element;
} else {
$this->current_field = '';
}
}
function end_element ($p, $element) {
$element = strtolower($element);
if ($this->ends_record[$element]) {
$this->records[] = $this->record;
$this->record = array( );
}
$this->current_field = '';
}
function cdata ($p, $text) {
if ($this->field_type[$this->current_field] === 2) {
$this->record[$this->current_field][] = $text;
} elseif ($this->field_type[$this->current_field] === 1) {
$this->record[$this->current_field] .= $text;
}
}
function show_menu( ) {
echo "\n";
foreach ($this->records as $book) {
echo "";
$authors = join(', ', $book['author']);
printf("\n",
$_SERVER['PHP_SELF'] . '?isbn=' . $book['isbn'],
$book['title'],
Example 11-10. bookparse.xml (continued)
,ch11.16545 Page 276 Wednesday, March 13, 2002 11:45 AM


This is the Title of the Book, eMatter Edition
Copyright © 2002 O’Reilly & Associates, Inc. All rights reserved.
%s%s

Download 6,9 Mb.

Do'stlaringiz bilan baham:
1   ...   61   62   63   64   65   66   67   68   69




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish