Page 1 of 1
[Solved] Getting data from a public website
Posted: Sun Aug 01, 2004 9:57 am
by Oxydude
I have a question about getting data from a website. I have a mysql file on my server with fields such as item, description, # pieces_bulk, color, etc. The item field is has valid items that I can access a webpage with. All of the other fields are blank. For instance, item 12345, I can generate a string for a webpage;
http://www.bigcompany.com/cgi-bin/products/?item=12345. This works, but what I want to do is write a script to grab data for description and other fields that are located on the page. Is this possible with PHP? Thanks!
Posted: Sun Aug 01, 2004 10:29 am
by feyd
sure is
example:
Code: Select all
<?php
// mysql connect here
$item = mysql_result($query, 1, 0);
$url = 'http://www.bigcompany.com/........' . $item;
$html = file_get_contents($url);
preg_match('#description:(.*?)pieces:(.*?)#is', $html, $matches);
var_dump($matches);
?>
Thanx
Posted: Sun Aug 01, 2004 1:37 pm
by Oxydude
Feyd,
Thanks! I will try it.
file_get_contents
Posted: Sun Aug 01, 2004 2:33 pm
by Oxydude
Is there a function similar to file_get_contents in PHP/4.0.6?
Fatal error: Call to undefined function: file_get_contents() in /var/www/html/nsb/getwordweb.php
Posted: Sun Aug 01, 2004 2:35 pm
by tim
4.0.6!!!!!!!!
whew you need to upgrade in the worst way.

Posted: Sun Aug 01, 2004 2:43 pm
by feyd

4.0.6... that's a bit old.. wow.. uh.. I'm not sure what functions were available at that point for opening remote files.. it looks like [php_man]fopen[/php_man] with url support was around at that point.
Re: file_get_contents
Posted: Sun Aug 01, 2004 2:49 pm
by d3ad1ysp0rk
Oxydude wrote:Is there a function similar to file_get_contents in PHP/4.0.6?
Fatal error: Call to undefined function: file_get_contents() in /var/www/html/nsb/getwordweb.php
Fopen and Fread do the same things.
Oh, and for the third time, upgrade!

Posted: Sun Aug 01, 2004 2:53 pm
by Oxydude
Thanks....I will upgrade. I am a newbie, and since my server is running, I hate to monkey with it. But once this is finished, I will upgrade. THanks for the help!
Posted: Mon Aug 02, 2004 5:34 pm
by Oxydude
I did upgrade to 4.3.8 last night....it wasn't as big a deal as I thought it would be. I will work on trying to grab the information using file_get_contents tonight. Thanks for the help!
Posted: Mon Aug 02, 2004 6:52 pm
by tim
wise choice on the upgrade, you'll enjoy php alot better on your road to mastering it. =]
Posted: Mon Aug 02, 2004 9:21 pm
by Oxydude
Listed below is my program:
<?php
$word = "test";
$html = file_get_contents('
http://www.bigcompany.com/cgi-bin/catalog?va=chair123');
echo $html
?>
When I call this program up in a browser, it will display the entire webpage chair123 with all of its details.
I am trying to get the only the shipping dimensions for the product and I tried adding the following:
preg_match("dimensions:", $html, $matches);
var_dump($matches);
I now get the following message: Warning: Delimiter must not be alphanumeric or backslash in /var/www/html/nsb/getwordweb.php on line 13
array(0) { }
What I need to do is read into a variable the 30 characters that follow the first instance of "Dimension:"
Is there a php command that will do this?
Thanks!
Posted: Tue Aug 03, 2004 10:24 am
by feyd
preg_match('#dimensions:(.*)#i',$html,$matches)
Posted: Tue Aug 03, 2004 10:29 am
by Oxydude
Thanks Feyd...i will try it out tonight.