Question

how can i get the price dynamically from another web page and store it in the server (php and SQL) if not in php it doesn't matter!

for example a web page that doesn't have json or xml but i want to get a specific value from it like the price

i tried a few things that are built in php but it didn't work the way i wanted to.

also this didn't work! :

Access-Control-Allow-Origin: *

i need this for my next project , i will really appreciate your help!

Was it helpful?

Solution

http://www.webmasterworld.com/forum88/10926.htm

How do I get the HTML code of a web page in PHP?

http://www.php.net/file_get_contents

You might start there. You will need to grab all of the HTML and then parse it based on the tags they are using.

From the first website (modified a bit):

$url = 'http://www.example.com'; 
$needle = '<b>find me</b>'; // Look for the tags on the other page and replace here
$contents = file_get_contents($url); 
if(strpos($contents, $needle) !== false) { 
    // Do your saving of the price here;
}

If you have more than one price on the page, you will need to form a loop that finds the next occurrence instead of only the first. Hopefully this helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top