JordanStreet Posted May 29, 2007 Share Posted May 29, 2007 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 ) Quote Link to comment https://forums.phpfreaks.com/topic/53480-regular-expression-accross-multiple-lines/ Share on other sites More sharing options...
MadTechie Posted May 29, 2007 Share Posted May 29, 2007 if (preg_match('%<div style="display:none;">(.*)</div>%si', $page, $description)) { $description= $description[0]; } else { $description= ""; } echo $description; Quote Link to comment https://forums.phpfreaks.com/topic/53480-regular-expression-accross-multiple-lines/#findComment-264354 Share on other sites More sharing options...
JordanStreet Posted May 30, 2007 Author Share Posted May 30, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/53480-regular-expression-accross-multiple-lines/#findComment-264410 Share on other sites More sharing options...
MadTechie Posted May 30, 2007 Share Posted May 30, 2007 almost to use Laziness Instead of Greediness, try this %<div style="display:none;">(.*?)</div>%si Quote Link to comment https://forums.phpfreaks.com/topic/53480-regular-expression-accross-multiple-lines/#findComment-264576 Share on other sites More sharing options...
JordanStreet Posted May 31, 2007 Author Share Posted May 31, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/53480-regular-expression-accross-multiple-lines/#findComment-265341 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.