Re bonjour,
Je vais vous mettre le code utilisé et les erreurs qu'il retourne ainsi cela pourra peut être vous aider a me guider.
Code :
Code :
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 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
<?php
function search($queryString) {
// Submit the query
$response = file_get_contents($queryString);
// Convert the response string to an XML object
return simplexml_load_string($response);
}
function getTotalResults($feed) {
// Get the namespaces used in the XML feed
$ns = $feed->getNamespaces(TRUE);
// Get the child nodes defined by the opensearch namespace
$openSearch = $feed->children($ns['opensearch']);
return (int) $openSearch->totalResults;
}
function getSearchTerms($feed) {
// Get the namespaces used in the XML feed
$ns = $feed->getNamespaces(TRUE);
// Get the child nodes defined by the opensearch namespace
$openSearch = $feed->children($ns['opensearch']);
// Get the Query Attributes
$queryAttributes = $openSearch->Query->attributes();
// Return the search terms
return $queryAttributes->searchTerms;
}
function getSpellCorrections($feed) {
// Get the namespaces used in the XML feed
$ns = $feed->getNamespaces(TRUE);
// Get the child nodes defined by the opensearch namespace
$openSearch = $feed->children($ns['opensearch']);
// Get the Query Attributes
foreach ($openSearch->Query as $query){
$queryAttributes = $query->attributes();
$corrString = (string) $queryAttributes->role;
if ($corrString == "correction") {
$spellCorrections[] = $queryAttributes->searchTerms;
}
}
// Return the spell corrections
return $spellCorrections;
}
function getStartIndex($feed) {
// Get the namespaces used in the XML feed
$ns = $feed->getNamespaces(TRUE);
// Get the child nodes defined by the opensearch namespace
$openSearch = $feed->children($ns['opensearch']);
return (int) $openSearch->startIndex;
}
function getResults($feed, $featLinks) {
$resultArray = array();
// Get the namespaces used in the XML feed
$ns = $feed->getNamespaces(TRUE);
// Get the child nodes defined by the opensearch namespace
$openSearch = $feed->children($ns['opensearch']);
// Extract each entry and display results
foreach ($feed->entry as $entry) {
$cat = (string)$entry->category['term']; //check for category entry
$catLen = strlen($cat);
if ($featLinks == TRUE) {
if ($catLen == 0) // no more category entries
break;
}
else if ($featLinks == FALSE) {
if ($catLen != 0) // ignore category entry
continue;
}
$result = new Result;
$result->title = (string) $entry->title;
$result->summary = (string) $entry->summary;
$result->link = (string) $entry->link['href'];
if ($featLinks == FALSE) {
$opensearchChild = $entry->children($ns['opensearch']);
$result->relevance = (string) $opensearchChild->relevance;
}
$resultArray[] = $result;
}
return $resultArray;
}
function getSearchResults($feed) {
$results = getResults($feed, FALSE);
return $results;
}
function getFeaturedLinks($feed) {
$results = getResults($feed, TRUE);
return $results;
}
class Result {
var $title;
var $summary;
var $link;
var $relevance;
function getTitle() {
return $this->title;
}
function getSummary() {
return $this->summary;
}
function getLink() {
return $this->link;
}
function getRelevance() {
return $this->relevance;
}
}
?> |
et voilà les erreurs retournées :
Citation:
Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 1: parser error : StartTag: invalid element name in C:\webdevdata\htdocs\recherche\oye.php on line 31
Warning: simplexml_load_string() [function.simplexml-load-string]: <!doctype html public "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/st in C:\webdevdata\htdocs\recherche\oye.php on line 31
Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in C:\webdevdata\htdocs\recherche\oye.php on line 31
Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 1: parser error : Extra content at the end of the document in C:\webdevdata\htdocs\recherche\oye.php on line 31
Warning: simplexml_load_string() [function.simplexml-load-string]: <!doctype html public "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/st in C:\webdevdata\htdocs\recherche\oye.php on line 31
Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in C:\webdevdata\htdocs\recherche\oye.php on line 31
Fatal error: Call to a member function getNamespaces() on a non-object in C:\webdevdata\htdocs\recherche\oye.php on line 36
|
Merci de m'aider a résoudre se problème.