I need to connect to the wikipedia search API. Here is an example response

    <search sroffset="10"/>
    <searchinfo totalhits="169717"/>
            <p ns="0" title="Intelligence quotient" timestamp="2013-04-04T05:15:12Z"/>
            <p ns="0" title="Test" timestamp="2013-02-23T01:15:05Z"/>
            <p ns="0" title="TeST Gliders" timestamp="2012-09-22T11:05:05Z"/>
            <p ns="0" title=".test" timestamp="2013-02-25T14:48:22Z"/>
            <p ns="0" title="Test cricket" timestamp="2013-04-02T18:49:54Z"/>
            <p ns="0" title="Test (assessment)" timestamp="2013-04-06T13:42:57Z"/>
            <p ns="0" title="Software testing" timestamp="2013-04-05T14:09:08Z"/>
            <p ns="0" title="Nuclear weapons testing" timestamp="2013-03-30T20:22:49Z"/>
            <p ns="0" title="Statistical hypothesis testing" timestamp="2013-04-02T22:06:07Z"/>
            <p ns="0" title="Standardized test" timestamp="2013-03-25T18:22:35Z"/>

What I want to be generated is

<li><a href="index.php?url=.../[Result 1 page name]">[Result 1 page name]</a></li>

And so on for each result.
Here's my php code

$query = $_GET['s'];
$xml = simplexml_load_file("https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch=$query&srprop=timestamp&format=xml");
$results = $xml->query->search->p;
$results_no = sizeof($results);

if ($results_no === 0){
    echo "Sorry! No results found";

echo "<ul>";

for ($i = 0; $i < $results_no ; $i++) {
    $title = $results[$i]->attributes()->title;
    $link = "<li><a href='/?url=https://en.wikipedia.org/wiki/$title'>$title</a></li>";
echo "</ul>";

But it just comes up with a blank page

Any help would be great!

Recommended Answers

All 2 Replies

You forgot to echo $link

That might have something to do with it!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.