Jump to content

[SOLVED] strops() and multiple instances of text


brettpower

Recommended Posts

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]

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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.