forked from hxseven/htmlSQL
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo_08.php
More file actions
executable file
·86 lines (58 loc) · 2.58 KB
/
Copy pathdemo_08.php
File metadata and controls
executable file
·86 lines (58 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
/*
** htmlSQL - Example 8
**
** Shows how to parse a RSS/XML file with htmlSQL
*/
include_once("../snoopy.class.php");
include_once("../htmlsql.class.php");
$wsql = new htmlsql();
// connect to the RSS URL (this URL contains new snippets from my codedump project)
if (!$wsql->connect('url', 'http://codedump.jonasjohn.de/rss/')){
print 'Error while connecting: ' . $wsql->error;
exit;
}
/* execute a query:
select the text attribute (alias for the tag content) from the <item> tag
*/
if (!$wsql->query('SELECT text FROM item')){
print "Query error: " . $wsql->error;
exit;
}
// fetch all results as objects:
foreach($wsql->fetch_objects() as $obj){
// create a new htmlsql object:
$sub_wsql = new htmlsql();
// connect to the <item> content:
$sub_wsql->connect('string', $obj->text);
// fetch all attributes of all tags:
if (!$sub_wsql->query('SELECT * FROM *')){
print "Query error: " . $wsql->error;
exit;
}
// this "special" function converts tagnames to keys
$sub_wsql->convert_tagname_to_key();
/* this function converts an array that looks like this:
$array[0]['tagname'] = 'title';
$array[0]['text'] = 'example 1';
$array[1]['tagname'] = 'link';
$array[1]['text'] = 'http://www.example.org/';
$array[2]['tagname'] = 'description';
$array[2]['text'] = 'description bla';
$array[2]['fulltext'] = '1'; // additional attribute
-> to:
$array['title']['text'] = 'example 1';
$array[1]['link']['text'] = 'http://www.example.org/';
$array[2]['description']['text'] = 'description bla';
$array[2]['description']['fulltext'] = '1'; // additional attribute
this makes the array easier to access
*/
// fetch item as array:
$item = $sub_wsql->fetch_array();
// format the extracted links as HTML links and output them:
print "<a href=\"" . $item['link']['text'] . "\">";
print $item['title']['text'] . "</a><br/>\n";
// also available:
// description, pubDate
}
?>