brettpower Posted October 18, 2007 Share Posted October 18, 2007 I am currently working with the below code to pull data out of one cell in my database. It works, however, I have two instances each of First Name, Last Name, Address Line1, Address Line2 and Address Line3. How do I, with strops(), pull the first and second instances of the above strings separately? Also, note the extra white space. How can I get rid of the excess white space? Also, there are three other sections I want to pull, however, because the number of lines will vary from customer to customer, I am stuck on how to pull them with strops() or preg_match. How do I pull data who's number of lines will vary? The strops() code is below as well as the data that I am pulling from. <?php $text = $row_View['details']; $find = array( '<b>SERVICE ADDRESS</b>', 'Last Name:', 'First Name:', 'Address Line 1:', 'Address Line 2:', 'City, State, ZIP:', '<br>', '<b>BILLING ADDRESS</b>', 'Last Name:', 'First Name:', 'Address Line 1:', 'Address Line 2:', 'City, State, ZIP:'); $offset = 1; foreach($find as $val) { $pos1 = strpos($text, $val, $offset) + strlen($val); $pos2 = strpos($text, "\n", $pos1); echo '<br />'.$val.' '.substr($text, $pos1 , ($pos2-$pos1) ); $offset = $pos2; } ?> Customer Information Getting Started One Time Fees: Digital Home Advantage Activation Fee $49.99 One Time Credits: Digital Home Advantage (Retail) $49.99 † One Time Cost: $49.99 Monthly Equipment Fees: DISH Network DVR Service Fee $5.98 Monthly Programming: America's Top 100 with Local Channels $34.99 Showtime Unlimited $12.99 DISH Home Protection Plan $5.99 Promotional Credits: DISH Home Protection Plan $5.99 †‡ Monthly Total $53.96 †Taxes are not included Click here for DISH Network DSL Sales. Select the appropriate link from the left side to modify this account. Status: CANCELLED NEW CONNECT DISH Bill Date: 00 BTN: (360)555-6666 Customer Code: N/A Can be Reached Number: (360)555-6666 DISH Account Number: 82256851245589526 Equipment No Equipment Available. Service Address Last Name: Power First Name: Brett Address Line 1: 5555 ANGLE DR Address Line 2: City, State, ZIP: OAK HARBOR, WA 98277-9607 Current Services .D DHA COMMIT +9 PREMIUMPICK ?? SALE PARTNER AA RECEIVER ACTIVATION D- DISHPRO TWIN LNBF }{ RETAIL DHA }} DISH HOME PROTECTION K: DHA18 QN ACTIVATION FEE T( INSTALL T$ DISH NETWORK SYSTEM XD DISH500KIT ZH DISH 500 Z8 110W ORBIT 2U 119W ORBIT 4W 2ND TUNR INS $= DHA LEASED RECEIVER AB AMERICA'S TOP 100 A6 SEATTLE WA LOCALS *1 DISH NETWORK DVR SERVICE D2 SHOWTIME UNLIMITED Billing Address Last Name: POWER First Name: BRETT Address Line 1: 5555 ANGLE DR Address Line 2: City, State, ZIP: OAK HARBOR, WA 98277-9607 Note History 06/22/07-18:34 MST ***CMO-REFUNDS*** CONF CC REFUND FOR $49.99 WAS SENT ON BATCH #VP062207A PLEASE ALLOW BUSINESS DAYS FOR BANK TO PROCESS 06/20/07-14:34 MST REFUND SUBMITTED DUE TO CANCELLED NEW CONNECT WORK ORDER 06/18/07-15:37 MST CANCEL WORK ORDER 92102220200011003 VIA E*CONNECT CUST REQUEST TOCANCEL W/O NEEDS TO GET LANDLORD PERMISSION WILL CB IF ABLE TO GET IT AND REBUILD W/O no problem-KENT EC111380 06/14/07-18:34 MST PAYMENT OF $49.99 POSTED TO ACCOUNT ON (DEBIT) CARD:6804.AUTHORIZATION NUMBER IS 515851.BATCH NUMBER IS:E1215 06/14/07-18:34 MST EMAN161 - PARTNER WEB DHA SALE ©2004 EchoStar Satellite, LLC. All Rights Reserved. " [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
effigy Posted October 18, 2007 Share Posted October 18, 2007 This may be of use. You may be better off with regular expressions depending on the format of the data. Is it always the same? Quote Link to comment Share on other sites More sharing options...
brettpower Posted October 18, 2007 Author Share Posted October 18, 2007 No. The length of the data and the characters that make it up will very each and every time. That is part of the problem. Although strops() does work to an extent as does preg_match, both fail to return the correct results for the second instances of the 3 address lines and first and last name. Quote Link to comment Share on other sites More sharing options...
effigy Posted October 18, 2007 Share Posted October 18, 2007 I was using a more flexible definition of "same" For instance, is an entry always going to start with a last name and end with a city/state/zip? Quote Link to comment Share on other sites More sharing options...
brettpower Posted October 18, 2007 Author Share Posted October 18, 2007 What you see in the array in the code above is what the data will always start with (that is unless Dish redesigns their site). What comes after that will absolutely change each and every single time. Quote Link to comment Share on other sites More sharing options...
effigy Posted October 18, 2007 Share Posted October 18, 2007 How about something like this? <pre> <?php $data = <<<DATA Select the appropriate link from the left side to modify this account. Status: CANCELLED NEW CONNECT DISH Bill Date: 00 BTN: (360)555-6666 Customer Code: N/A Can be Reached Number: (360)555-6666 DISH Account Number: 82256851245589526 Equipment No Equipment Available. Service Address Last Name: Power First Name: Brett Address Line 1: 5555 ANGLE DR Address Line 2: City, State, ZIP: OAK HARBOR, WA 98277-9607 Current Services .D DHA COMMIT +9 PREMIUMPICK DATA; preg_match('/Service Address\s+(.+?)^\s*$/sm', $data, $matches); print_r($matches); $pieces = preg_split('/:|\r?\n/', $matches[1], -1, PREG_SPLIT_NO_EMPTY); $size = count($pieces); for ($index = 0; $index < $size; $index++) { if ($index % 2 == 0) { $info[$pieces[$index]] = trim($pieces[++$index]); } } print_r($info); ?> </pre> Quote Link to comment Share on other sites More sharing options...
brettpower Posted October 18, 2007 Author Share Posted October 18, 2007 Check your PM. Quote Link to comment Share on other sites More sharing options...
effigy Posted October 18, 2007 Share Posted October 18, 2007 Why the PM? To also match the billing address and output: preg_match_all('/(?:Service|Billing) Address\s+(.+?)^\s*$/sm', $data, $matches, PREG_PATTERN_ORDER); foreach ($matches[1] as $line) { echo $line, '<br>'; } Quote Link to comment Share on other sites More sharing options...
brettpower Posted October 18, 2007 Author Share Posted October 18, 2007 The PM was just to help explain where I was going and where the data was destined to. Quote Link to comment Share on other sites More sharing options...
brettpower Posted October 18, 2007 Author Share Posted October 18, 2007 It still amazes me as to how darn many ways there are to do things in PHP! Quote Link to comment Share on other sites More sharing options...
effigy Posted October 18, 2007 Share Posted October 18, 2007 Is this topic solved now? It still amazes me as to how darn many ways there are to do things in PHP! You should see Perl. Quote Link to comment Share on other sites More sharing options...
brettpower Posted October 18, 2007 Author Share Posted October 18, 2007 Yup. It sure is. Totally solved. Thanks for the lesson. Quote Link to comment 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.