[SOLVED] Reading a webpage question

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] Reading a webpage question

Post by Oxydude »

Listed below is my program:

Code: Select all

<?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:

Code: Select all

preg_match("dimensions:", $html, $matches);

var_dump($matches);
I now get the following message:

Code: Select all

Warning: Delimiter must not be alphanumeric or backslash in /var/www/html/nsb/getwordweb.php on line 13
array(0) &#123; &#125;
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!

[Edit: Fixed subject & added php and code tags. --JAM]
Last edited by Oxydude on Tue Aug 03, 2004 7:16 pm, edited 1 time in total.
Oxydude
Forum Newbie
Posts: 22
Joined: Sun Aug 01, 2004 9:57 am

Reading a webpage question

Post by Oxydude »

When I posted, I didn't use a subject. I hope this corrects it.
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

You can fumble your way though with something like:

Code: Select all

$html = file_get_contents('http://www.bigcompany.com/cgi-bin/catalog?va=chair123'); 
$data = explode("Dimension:", $html);
$result = substr($data[1],0,30);
echo $result;
But your probably best off using a regex.
Oxydude
Forum Newbie
Posts: 22
Joined: Sun Aug 01, 2004 9:57 am

Thanks!

Post by Oxydude »

Kettle Drum,

Thanks for the response! I will try it tonight.
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Re: Reading a webpage question

Post by JAM »

Oxydude wrote:When I posted, I didn't use a subject. I hope this corrects it.
Not really, as you need to [edit] the original post to change it. But allow me. ;)
Oxydude
Forum Newbie
Posts: 22
Joined: Sun Aug 01, 2004 9:57 am

Post by Oxydude »

thanx jam!
Post Reply