Queries MSN Search API*

เริ่มโดย ggynmsn, 04 สิงหาคม 2007, 01:55:32

หัวข้อก่อนหน้า - หัวข้อถัดไป

0 สมาชิก และ 1 ผู้มาเยือน กำลังดูหัวข้อนี้

ggynmsn

 :)

<?php
/**
* This set of functions queries MSN Search API.
*
* This is a single php page and set of functions that, when given the right
* data will return a set of formatted MSN search results. Requires NuSOAP,
* located at http://sourceforge.net/projects/nusoap/.
* Stick this file into a folder in your server along with NuSOAP
* library and point your browser there for action. Don't forget to get
* an MSN Application ID (see http://search.msn.com/developer)
*
* Read the related blog post here:
* http://www.fiftyfoureleven.com/weblog/web-development/programming-and-scripts/apis/msn-search-api
*
* @author: Mike Papageorge, http://www.fiftyfoureleven.com/contact
* @lastUpDate: 14/11/2005
* @license: http://creativecommons.org/licenses/by/2.5/
* @location: http://www.fiftyfoureleven.com/site/code/msn-search-api-sample.txt
*/
   error_reporting(E_ALL);

// Variables for the search. You need to edit these to use this:

   $id       = 'your msn api';
   $site       = 'www.yourdomain.com';
   $numresults   = 30;
   $baseurl    = 'http://soap.search.msn.com/webservices.asmx';; // MSN API URI
   $form       = '
            <form action="'.$_SERVER['PHP_SELF'].'" method="get">
               <label for="p">Search Terms</label>
               <input name="p" id="p" type="text" />
               <input type="submit" value="search" />
            </form>
         
         ';

/**
* A little 'controller' to make this sample page work:
*
*/
   $xhtml = '';
   if(isset($_GET['p']) && $_GET['p'] != '') {
      $data = getResultArray($id, $site, $baseurl, $numresults);
      $xhtml = $form.formatMSNResultset($data, $numresults);
   } else {
      // If an empty search was given:
      $xhtml = (isset($_GET['p']) && $_GET['p'] == '') ? '<p>Please enter a search term</p>':'';
      // Show the form:
      $xhtml .= $form;
   }

   echo $xhtml;


//
//
//   Here be functions....
//
//

/**
* Build an array with the parameters we want to use.
*
*/
   function setParams($id, $site, $numresults) {
      $params = array(
         // Details for all of these can be found in the developer's kit,
         // in the help file.
         'AppID' => $id,
         'Query' => "site:$site $_GET[p]",
         'CultureInfo' => 'en-US',
         'SafeSearch' => 'Off',
         'Requests' => array (
            'SourceRequest' => array (
               'Source'       => 'Web',
               'Offset'       => 0,
               'Count'       => $numresults,
               'ResultFields'    => 'All'
            )
         )
      );
      return $params;
   }


/**
* This function passes our data to NuSOAP, and
* returns the search results:
*/      
   function getResultArray($id, $site, $baseurl, $numresults) {
      // Get the parameters:
      $params = setParams($id, $site, $numresults);
      // Include the library:
      include_once("nusoap.php");
      // Create a instance of the SOAP client object
      $soapclient = new soapclient($baseurl);
      $data = $soapclient->call("Search", array("Request"=>$params));
      return $data;
   }


/**
* This function formats our MSN specific array:
*
*/
function formatMSNResultset($data, $numresults) {
      // If no results were found:
      if($data['Responses']['SourceResponse']['Total'] == '0') {
         $results = '<p>There were 0 results found with MSN search. Please try again by typing your search terms into the search box, and then click search.</p>';
         return $results;
      }
      
      // Now down to business:
      $tmp = '';
      foreach($data['Responses']['SourceResponse']['Results']['Result'] as $key => $value) {
         $tmp .= '<dt><a href="'.$data['Responses']['SourceResponse']['Results']['Result'][$key]['Url'].'">'.$data['Responses']['SourceResponse']['Results']['Result'][$key]['Title'].'</a></dt>
         ';
         $r = htmlentities($data['Responses']['SourceResponse']['Results']['Result'][$key]['Description']);
         $tmp .= '<dd>'.$r.'</dd>
         
         ';
      }
      $results = '<h1>Viewing '.$numresults.' of '.$data['Responses']['SourceResponse']['Total'].' results found by MSN search.</h1>
      <dl>
      '.$tmp.'
      </dl>';
      
      return $results;
   }

?>

ColdMoney

[direct=https://www.jumnong.com]รับจำนอง[/direct] [direct=https://burapasup.com]รับซื้อบ้าน[/direct] [direct=https://kadsan.com]สินค้าราคาถูก[/direct] [direct=https://checkcheap.com]เปรียบเทียบราคา[/direct]

xvlnw.com

ใช้ทำอะไรครับ ??
[direct=https://cloudhost.in.th/wordpress-hosting]ツ ⓌⓄⓇⒹⓅⓇⒺⓈⓈ ⒽⓄⓈⓉⒾⓃⒼ [/direct] :wanwan014:  :D
[direct=https://cloudhost.in.th/cloudhosting.html]Cloud Hosting[/direct] [direct=https://cloudhost.in.th/cloudvps.html]Cloud Server[/direct] [direct=https://cloudhost.in.th/vpshosting.html]Cloud VPS Hosting[/direct] [direct=https://cloudhost.in.th/windowsvps.html]Cloud Windows[/direct] Tel: 080-348-0843 LINE: ixvlnw

issara2008

Come celebrate with us on BlackFriday!