Skip to content

Instantly share code, notes, and snippets.

@zag2me
Created November 13, 2015 13:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zag2me/efb0d6769aeba1bdd948 to your computer and use it in GitHub Desktop.
Save zag2me/efb0d6769aeba1bdd948 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<title>Ebay Finder</title>
</head>
<body>
<p>Enter the Ebay URL</p>
<?php
// Function to find the text from the left in a string
function strleft($str, $separator) {
if (intval($separator)) {
return substr($str, 0, $separator);
} elseif ($separator === 0) {
return $str;
} else {
$strpos = strpos($str, $separator);
if ($strpos === false) {
return $str;
} else {
return substr($str, 0, $strpos);
}
}
}
// Display a form for the URL if not posted
if ($_POST["fname"] == NULL) {
echo "<img src='logo.jpg'><br><br>";
echo "<form action='index.php' method='post' autocomplete='off'><input type='text' name='fname' id='inputString' size='75'/></form>";
}
// Show the search results
else {
$ebayURL = addslashes($_POST["fname"]);
echo "<img src='logo.jpg'><br> Searching... ($ebayURL)<br><br>";
//echo $ebayURL;
$html = file_get_contents($ebayURL);
$dom = new DOMDocument();
@$dom->loadHTML($html);
// grab all the on the page
$xpath = new DOMXPath($dom);
$hrefs = $xpath->evaluate("/html/body//a");
for ($i = 0; $i < $hrefs->length; $i++) {
$href = $hrefs->item($i);
$url = $href->getAttribute('href');
// Only show URL's with the item number "itm" in the string
if (strpos($url,'itm') !== false) {
// Cut the URL from the left after "?hash" and get the last 12 characters (ebayid)
echo substr(strleft($url, "?hash"),-12).'<br />';
}
}
}
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment