omdat het vorige topic (\[php+rss] <content:encoded> parsen) is gesloten beschrijf ik het probleem wat duidelijker .
Ik heb een script om vanuit een RSS data naar mysql web te schrijven. Zoals hieronder te zien is kun je bijvoorbeeld vanaf <description> tm </description> alles parsen. Dit werkt gelukkig allemaal heel goed. Alleen in RSS2.0 zit een tag die ik maar niet geparsed krijg.
Dit is <content:encoded>.
Ik zit al 3 avonden te proberen maar ik kom er echt niet uit
. Nu bestaan er kant en klare classes e.d. die dit kunnen maar ditr script voldoet.
Heeft iemand enig idee hoe ik dit kan doen? Of wie kan mij op weg helpen?
Ik heb een script om vanuit een RSS data naar mysql web te schrijven. Zoals hieronder te zien is kun je bijvoorbeeld vanaf <description> tm </description> alles parsen. Dit werkt gelukkig allemaal heel goed. Alleen in RSS2.0 zit een tag die ik maar niet geparsed krijg.
Ik zit al 3 avonden te proberen maar ik kom er echt niet uit
Heeft iemand enig idee hoe ik dit kan doen? Of wie kan mij op weg helpen?
PHP:
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
| <?php $connection = mysql_connect("x", "x_x", "x"); mysql_select_db("x", $connection); $counter = 0; $type = 0; $tag = ""; $itemInfo = array(); $channelInfo = array(); function unhtmlspecialchars( $string ) { $string = str_replace ( '&', '&', $string ); $string = str_replace ( ''', '\'', $string ); $string = str_replace ( '"', '\"', $string ); $string = str_replace ( '<', '<', $string ); $string = str_replace ( '>', '>', $string ); return $string; } function opening_element($xmlParser, $name, $attribute){ global $tag, $type; $tag = $name; if($name == "CHANNEL"){ $type = 1; } else if($name == "ITEM"){ $type = 2; } }//end opening element function closing_element($xmlParser, $name){ global $tag, $type, $counter; $tag = ""; if($name == "ITEM"){ $type = 0; $counter++; } else if($name == "CHANNEL"){ $type = 0; } }//end closing_element function c_data($xmlParser, $data){ global $tag, $type, $channelInfo, $itemInfo, $counter; $data = trim(htmlspecialchars($data)); if($tag == "TITLE" || $tag == "DESCRIPTION" || $tag == "THUMB" || $tag == "LINK"){ if($type == 1){ $channelInfo[strtolower($tag)] = $data; }//end checking channel else if($type == 2){ $itemInfo[$counter][strtolower($tag)] .= $data; }//end checking for item }//end checking tag }//end cdata funct $xmlParser = xml_parser_create(); xml_parser_set_option($xmlParser, XML_OPTION_CASE_FOLDING, TRUE); xml_parser_set_option($xmlParser, XML_OPTION_SKIP_WHITE, TRUE); xml_set_element_handler($xmlParser, "opening_element", "closing_element"); xml_set_character_data_handler($xmlParser, "c_data"); $fp = file($_GET['rss']); foreach($fp as $line){ if(!xml_parse($xmlParser, $line)){ die("Could not parse file."); } } foreach($itemInfo as $items){ $query = mysql_query("SELECT * FROM stories WHERE title = '".htmlentities($items['title'], ENT_QUOTES)."'") or die(mysql_error()); $num = mysql_num_rows($query); if($num > 0){ echo $items['title']." already exists!<br />"; } else { $items2['description'] = unhtmlspecialchars ($items['description']); if (mysql_query("INSERT INTO stories VALUES('', '".htmlentities($items['title'], ENT_QUOTES)."', '".htmlentities($items2['description'], ENT_QUOTES)."', '".htmlentities($items['link'],ENT_QUOTES)."')") or die(mysql_error())){ echo $items['title']." was added!<br />"; } } } ?> |