Page 1 of 1

[SOLVED] Reading a webpage question

Posted: Mon Aug 02, 2004 8:34 pm
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]

Reading a webpage question

Posted: Mon Aug 02, 2004 9:19 pm
by Oxydude
When I posted, I didn't use a subject. I hope this corrects it.

Posted: Mon Aug 02, 2004 11:23 pm
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.

Thanks!

Posted: Tue Aug 03, 2004 7:17 am
by Oxydude
Kettle Drum,

Thanks for the response! I will try it tonight.

Re: Reading a webpage question

Posted: Tue Aug 03, 2004 8:42 am
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. ;)

Posted: Tue Aug 03, 2004 5:38 pm
by Oxydude
thanx jam!