Jump to content

Recommended Posts

I am creating a PHP script that will take a downloaded web page (in html format) and pull certain information out of the page.

 

Here is what I have:

 

<?

$location = 'requests/1.htm';		
$page = file_get_contents($location);

// get the title
preg_match('{<title>Buy (.*) At Sam Ash</title>}',$page,$title);
$title = $title[1];
echo "$title <p/>";

// get the product id
preg_match('{var pr_page_id = \'(.*)?\';}',$page,$id);
$id = $id[1];
echo "$id <p/>";

// get the price
preg_match('{color: #990000;">\$(.*)?</font>}',$page,$price);
$price = $price[1];
$price = $price * 1.17;
$price = round($price,2);
echo "$price <p/>";

// get the description
preg_match('{<div style="display:none;">(.*)</div>}',$page,$description);
print_r($description);

?>

 

Everything works fine except for this part

 

// get the description
preg_match('{<div style="display:none;">(.*)</div>}',$page,$description);
print_r($description);

 

the part of the html that this applies to looks like this

 

<div style="display:none;"><P>Derived from a mahogany body/neck and headstock in conjunction with a solid spruce top, the EA15TR produces a full range of sound with a wide range of dynamics. The large body teamed up with the solid top, allows the pristine and crystal high notes to blend perfectly with the full, well rounded bass. 21 frets sit on top of a rosewood fingerboard bound in white. The top and back of the body are bound with multi-ply bright white binding that when coupled with the abalone rosette around the sound hole, ties this guitar together visually. On stage dial in the exact sound you desire with the B-Band preamp. While on that stage the EA15TR is sure to stay in tune with the Chrome Grover tuners.  This guitar is an all around work horse that will reward you with countless hours of playing enjoyment. Case not included.</P>
<P><STRONG>Specifications:</STRONG></P>
<UL>
<LI>Mahogany body 

<LI>Solid spruce top 
<LI>Mahogany neck 
<LI>Rosewood fingerboard 
<LI>B-Band electronics 
<LI>Chrome Grover tuners 
<LI>Abalone sound hole inlay 
<LI>Diamond inlays</LI></UL>
<P><B>Washburn Limited Lifetime Warranty<BR></B>Washburn instruments are warranted to be free from defective material and workmanship from the date of purchase to the original purchaser when purchased from an authorized Washburn dealer. The Washburn Limited Lifetime Warranty covers repair parts and labor.</P>
<P></P>
<P>Washburn will repair or replace, at its option, any Washburn instrument or part thereof which is found by Washburn to be defective. </P></div>

 

you can view it in action here http://guitarvideos.org/store/samashbot/

 

Thanks guys, I appreciate your time reading this (and hopefully responding :P )

awsome, I understand what you did :)  There is still 1 question I have

 

{<div style="display:none;">(.*)</div>}sU

 

it stops at the first </div>

 

but when I do

 

{<div style="display:none;">(.*)?</div>}s

 

it keeps going

 

can you help me with that ?

 

 

thanks,

Jordan

alright Thanks man I appreciate it :)

 

To summarize for anyone having this provlem.

 

1)  I needed to ad the "s" at the end of the regex to make it so the "." stands for any character INCLUDING new line

 

2)  To add laziness to my regex I needed to use the "?" at the end of the sub patern although I'm not sure why it has to be inside the sub partern instead of right after it.

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.