搜尋
首頁php教程php手册如何用PHP把RDF内容插入Web站点之中(4)

 

// this is an array of arrays, with each array element representing an
// each outer array element is itself an associative array
// with keys ("title", "link", "description")
$items = array(),

// opening tag handler
function elementBegin($parser, $name, $attributes)
{
global $currentTag, $flag,
$currentTag = $name,
// set flag if entering or block
if ($name == "ITEM")
{
$flag = 1,
}
else if ($name == "CHANNEL")
{
$flag = 2,
}
}

// closing tag handler
function elementEnd($parser, $name)
{
global $currentTag, $flag, $count,
$currentTag = "",

// set flag if exiting or block
if ($name == "ITEM")
{
$count++,
$flag = 0,
}
else if ($name == "CHANNEL")
{
$flag = 0,
}
}

// character data handler
function characterData($parser, $data)
{
global $currentTag, $flag, $items, $count, $channel,
$data = trim(htmlspecialchars($data)),
if ($currentTag == "TITLE" || $currentTag == "LINK" ||
$currentTag ==
"DESCRIPTION")
{
// add data to $channels[] or $items[] array
if ($flag == 1)
{
$items[$count][strtolower($currentTag)] .=
$data,
}
else if ($flag == 2)
{
$channel[strtolower($currentTag)] .= $data,
}
}

}

// create parser
$xp = xml_parser_create(),

// set element handler
xml_set_element_handler($xp, "elementBegin", "elementEnd"),
xml_set_character_data_handler($xp, "characterData"),
xml_parser_set_option($xp, XML_OPTION_CASE_FOLDING, TRUE),
xml_parser_set_option($xp, XML_OPTION_SKIP_WHITE, TRUE),

// read XML file
if (!($fp = fopen($file, "r")))
{
die("Could not read $file"),
}

// parse data
while ($xml = fread($fp, 4096))
{
if (!xml_parse($xp, $xml, feof($fp)))
{
die("XML parser error: " .
xml_error_string(xml_get_error_code($xp))),
}
}

// destroy parser
xml_parser_free($xp),

// now iterate through $items[] array
// and print each item as a table row
foreach ($items as $item)
{
echo "tr
>

href=" . $item["link"] . ">" . $item["title"] .
"
br>" . $item["description"] . " tr>", }

?>

陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

Atom編輯器mac版下載

Atom編輯器mac版下載

最受歡迎的的開源編輯器

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

將Eclipse與SAP NetWeaver應用伺服器整合。

Dreamweaver Mac版

Dreamweaver Mac版

視覺化網頁開發工具

VSCode Windows 64位元 下載

VSCode Windows 64位元 下載

微軟推出的免費、功能強大的一款IDE編輯器

WebStorm Mac版

WebStorm Mac版

好用的JavaScript開發工具