[Solved] Getting data from a public website

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Oxydude
Forum Newbie
Posts: 22
Joined: Sun Aug 01, 2004 9:57 am

[Solved] Getting data from a public website

Post 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!
Last edited by Oxydude on Tue Aug 03, 2004 7:16 pm, edited 2 times in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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);

?>
Oxydude
Forum Newbie
Posts: 22
Joined: Sun Aug 01, 2004 9:57 am

Thanx

Post by Oxydude »

Feyd,

Thanks! I will try it.
Oxydude
Forum Newbie
Posts: 22
Joined: Sun Aug 01, 2004 9:57 am

file_get_contents

Post 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
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

4.0.6!!!!!!!!

whew you need to upgrade in the worst way.

:wink:
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

8O 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.
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Re: file_get_contents

Post 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! :P
Oxydude
Forum Newbie
Posts: 22
Joined: Sun Aug 01, 2004 9:57 am

Post 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!
Oxydude
Forum Newbie
Posts: 22
Joined: Sun Aug 01, 2004 9:57 am

Post 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!
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

wise choice on the upgrade, you'll enjoy php alot better on your road to mastering it. =]
Oxydude
Forum Newbie
Posts: 22
Joined: Sun Aug 01, 2004 9:57 am

Post 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!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

preg_match('#dimensions:(.*)#i',$html,$matches)
Oxydude
Forum Newbie
Posts: 22
Joined: Sun Aug 01, 2004 9:57 am

Post by Oxydude »

Thanks Feyd...i will try it out tonight.
Post Reply