note 51637 added to ref.xml

From: Date: Wed, 06 Apr 2005 09:31:12 +0000
Subject: note 51637 added to ref.xml
Groups: php.notes 
Request: Send a blank email to php-notes+get-87562@lists.php.net to get a copy of this message
to import xml into mysql $file = "article_2_3032005467.xml"; $feed = array(); $key = ""; $info = ""; function startElement($xml_parser, $attrs ) { global $feed; } function endElement($xml_parser, $name) { global $feed, $info; $key = $name; $feed[$key] = $info; $info = ""; } function charData($xml_parser, $data ) { global $info; $info .= $data; } $xml_parser = xml_parser_create(); xml_set_element_handler($xml_parser, "startElement", "endElement"); xml_set_character_data_handler($xml_parser, "charData" ); $fp = fopen($file, "r"); while ($data = fread($fp, 8192)) !xml_parse($xml_parser, $data, feof($fp)); xml_parser_free($xml_parser); $sql= "INSERT INTO article ( `"; $j=0; $i=count($feed); foreach( $feed as $assoc_index => $value ) { $j++; $sql.= strtolower($assoc_index); if($i>$j) $sql.= " , "; if($i<=$j) {$sql.= "` ) VALUES ('";} } $h=0; foreach( $feed as $assoc_index => $value ) { $h++; $sql.= utf8_decode(trim(addslashes($value))); if($i-1>$h) $sql.= "', '"; if($i<=$h) $sql.= "','')"; } $sql=trim($sql); echo $sql; ---- Manual Page -- http://www.php.net/manual/en/ref.xml.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+51637 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51637&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51637&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51637&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51637&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51637&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+51637&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#87562) next »