1000 posts // to tag, you need to use 'limit' in your query. See comment #1 on the 2nd weblog link above for more info. $contentRow = 'content'; // The row that your content is held in. For example in // "select id, content from weblog", 'content' would be $contentRow. include('xml.php'); // Include Keith Devens XML library: http://keithdevens.com/software/phpxml // Table for the data: /* CREATE TABLE `post2tag` ( `id` int(11) NOT NULL auto_increment, `tagvalue` varchar(255) NOT NULL default '', `post_id` smallint(6) NOT NULL default '0', `tag_id` smallint(6) NOT NULL default '0', PRIMARY KEY (`id`) ); */ // // // Here's all the action: // // // Connect to our DB if(!$link = mysql_connect($host, $user, $pass)) {die('no connection');} if(!mysql_select_db($db)) {die('no db');} // Get our result: if(!$result = mysql_query($query)) {die('query error');} // Start the while loop: while($row = mysql_fetch_array($result)) { // Here's a switch for choosing which API we're using: if($mode == 'Yahoo!') { $url = "http://api.search.yahoo.com/ContentAnalysisService/V1/termExtraction"; // Yahoo! $querystring = "appid=$yahooAppId&context=$row[$contentRow]"; // Yahoo! echo $querystring; } elseif($mode == 'Tagyu') { $url = 'http://tagyu.com/api/suggest/'; // Tagyu $querystring = "suggest=$row[$contentRow]"; // Tagyu } else die('Mode is set incorrectly'); // Initialize a curl handle: $ch = curl_init(); // Now we start to set some of the options: // Set request method to POST curl_setopt($ch, CURLOPT_POST, 1); // Pass the url that we're posting to: curl_setopt($ch, CURLOPT_URL, $url); // Tell cURL to return the data into a variable: curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // Set a timeout value for connecting to the server, in seconds: curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15); // Set a timeout value for the entire process, in seconds: ****!!!! curl_setopt($ch, CURLOPT_TIMEOUT, 15); // To Pass a username and password: ($mode == 'Tagyu') ? curl_setopt($ch, CURLOPT_USERPWD, "$username:$password"):''; // Pass the query string to the handle: curl_setopt($ch, CURLOPT_POSTFIELDS, $querystring); // Execute the request! $chresult = curl_exec($ch); // run the whole process // Close our handle: curl_close($ch); // Have a look at the XML: uncomment the following two lines - this 'exits' here, so it won't affect your DB. // header("Content-type: application/xml"); // echo $chresult;exit; // Sleep 1 second to be polite to the API server. sleep(1); // Pass the result to our XML library and unserialize the data: $data = XML_unserialize($chresult); // Have a look at $data: uncomment the following line - this 'exits' here, so it won't affect your DB. // echo '
';print_r($data);echo '
';exit; // Here we put the result data into $r so we only need one foreach below: if($mode == 'Yahoo!') { $r = $data['ResultSet']['Result']; // Yahoo! data } else { $r = $data['suggestions']['tag']; // Tagyu data } foreach($r as $value) { $tagquery = "insert into $table set tagvalue='$value', post_id = $row[id]"; $tagresult = mysql_query($tagquery); } } ?>