I want to find the info about things in eBay by URL.
I tried this but it's not working:
<?php
$web = file_get_contents('http://www.ebay.com/itm/7-inch-Android-4-2-A13-Capacitive-Touch-Screen-WiFi-Tablet-PC-Front-Camera-8GB/361031774590');
$title = preg_replace('~(.*)<span class="g-hdn">(.*)</span>~','',$web);
$title = preg_replace('~</h1><h2 id="subTitle" class="it-sttl">(.*)~','',$title);
echo $title;
?>
Alternatively, you could also use (as halfer suggested) DOMDocument
with xpath to get them, and its easier to use their id
's instead. Example:
$url = 'http://www.ebay.com/itm/7-inch-Android-4-2-A13-Capacitive-Touch-Screen-WiFi-Tablet-PC-Front-Camera-8GB/361031774590';
$dom = new DOMDocument();
libxml_use_internal_errors(true);
$dom->loadHTMLFile($url);
libxml_clear_errors();
$xpath = new DOMXPath($dom);
$title = $xpath->query('//h1[@id="itemTitle"]')->item(0)->lastChild->nodeValue;
$description = $xpath->query('//h2[@id="subTitle"]')->item(0)->nodeValue;
echo $title . '<br/>';
echo $description;
I think a better approach would be to extract the item number from the URL, then make an API call to eBay to retrieve item information. (The eBay API is free to sign up, and you can start using it immediately.)
A quick and easy way to extract the item# from the URL is to pull out the first 10-13 digit number. There'll be some rare edge cases where this won't work (like a long part number in the item title), but I wouldn't worry about that.
And instead of the API, you can also consider using eBay's RSS feeds to retrieve the data you want.