I'm trying to customize a php library administration system to fit my needs. In the system, when I choose to add a book, I'm taken to a page asking to enter ISBN(ASIN). I type it and I accept, then I'm taken to a page to fill the rest of the info about the book. Well, the whole question is about lazyness: I need the system to check ISBNdb.com (a public ISBN database) for that book and fill the data for me. Till now, I've managed to check the information, but I'm an absolute newbie and I don't know how can I ask php to analyze the XML answer from ISDNdb and drop the information on an array. I don't even know how to define an array, indeed.
XML answer is something like that:

<ISBNdb server_time="2007-03-05T01:40:40Z">
<BookList total_results="1" page_size="10" page_number="1" shown_results="1">
<BookData book_id="works_of_oscar_wilde" isbn="1851705384">
<Title>Works of Oscar Wilde</Title>
<TitleLong/>
<AuthorsText>Oscar Wilde, Timothy Gaynor (Editor)</AuthorsText>
<PublisherText publisher_id="senate">Senate</PublisherText>
<Details dewey_decimal="" physical_description_text="800 pages" language="" edition_info="Unknown Binding; 1997-07-25" dewey_decimal_normalized="" lcc_number="" change_time="2007-03-05T00:10:26Z" price_time="2007-03-05T00:10:47Z"/>
</BookData>
</BookList>
</ISBNdb>

I need, then, to have the text between <Title> and </Title> in $o_livre->Title
the one between <AuthorsText> and </AuthorsText> in $o_livre->AuthorsText
the publisher in $o_livre->PublisherText
the text after edition_info=" and before the ; (Unknown Binding) in $o_livre->Lieu
and the date after the ; in $o_livre->ReleaseDate
I'm calling to a function in the main php file this way:

$o_livre=get_book_isbn($rechcode)

and the function, in functions.inc, is:

function get_book_isbn($rechcode)
{
$return=readfile('http://isbndb.com/api/books.xml?access_key=XXXXXXXX&results=details&index1=isbn&value1='.$rechcode);
return($return);
}

HELP PLEASE!
Many thanks for your help!

    If you're running PHP5, the [man]SimpleXML[/man] functions are fairly simple to use.

      I'm using PHP5 and I gave a look to the function you said... the code I have now is:

      function get_book_isbn($rechcode)
      {
      $url = 'http://isbndb.com/api/books.xml?access_key=XXXXXXXX&results=details&index1=isbn&value1='.$rechcode);
      $xml = simplexml_load_file($url);
      return($xml);
      }

      Giving back no results... I'm actually a newbie and I can't figure out how to do that...
      Many thanks for your help.

        <?php
        function get_book_isbn($rechcode)
        {
           $url = 'http://isbndb.com/api/books.xml?access_key=XXXXXXXX&results=details&index1=isbn&value1='.$rechcode);
           $xml = simplexml_load_file($url);
           if($xml !== FALSE)
           {
              $result = array();
              $result['Title'] = sprintf('%s',$xml->BookList->BookData[0]->Title);
              $result['AuthorsText'] = sprintf('%s', $xml->BookList->BookData[0]->AuthorsText);
              $result['PublisherText'] = sprintf('%s', $xml->BookList->BookData[0]->PublisherText);
              $parts = explode(';', sprintf('%s', $xml->BookList->BookData->Details['edition_info']));
              $result['Lieu'] = $parts[0];
              $result['ReleaseDate'] = trim($parts[1]);
              return($result);
           }
           else
           {
              return(FALSE);
           }
        }
        $o_livre = get_book_isbn(1);
        // show result:
        echo "<pre>".print_r($o_livre, TRUE)."</pre>";
        ?>
        

          Thanks for your very useful help, I'm really happy with the results. I need only one more fine tunning to have it perfectly working:
          I've just realized ISBNdb (not the code you gave me) appends always a ", " after the name of the author. Do you know how can I cut it?
          Many, really many thanks for your help!

            Just use trim($variable, ',') to get rid of leading/trailing commas, e.g.:

            $result['AuthorsText'] = trim($result['AuthorsText'], ',');
            
              7 days later

              Well, I still have a little problem:
              Sometimes I got data and I think this is caused by the information not returning quick enough, because if I go back and try again I got all the data. So... how can I make the function stop till it gets the XML response?
              Thank you very much!

                Write a Reply...