Forum Moderators: coopster

Message Too Old, No Replies

parsing text file

         

kadnan

10:43 am on Jul 15, 2004 (gmt 0)

10+ Year Member



hi
i have to parse a text file having content of SWIFT(http://swift.com) messages

the file is like a report text file in which certain titles are repeated...
=====================================================

U-UMID = OBKTRUS33XXX940ST041839435092312
Suffix = 040710

Status =
Read-Only


Format = Swift Sub-Format = Output
<b>Msg Type = 940</b> Nature = Financial

<b>Sender</b> =
BETRES33RAX</b> LT : A

DEUTSCHE BANK TRUST COMPANY AMERICAS

NEW YORK,NY 10004
NEW YORK,NY
US
UNITED STATES


<b>Receiver</b> =
ADFHEKKAADC</b> LT : A

BANK NAME

Address

=======================================================

the text file having bold fields will be repeated again and again

i was thinking to use preg_match_all to extract the bold fields and put them in database
can u help me this regard that which method will be useful for me

i tried preg_match_all liked that
preg_match_all ("(U-UMID)", $alltext, $matches);

its extracitng all matches of "U-UMID" but when i add another searching string like that

preg_match_all ("(U-UMID)(Sender)", $alltext, $matches);

then it doesnt print anything..kindly help me for this

thanks

-adnan

coopster

2:21 pm on Jul 15, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You're getting close, but you said you want everything between the bold tags, correct?
$patterns = "/<b>(.*)<\/b>/Uis"; 
preg_match_all($patterns, $input, $matches);
// Wanna see what you get?
print '<pre>'; print_r($matches); exit('</pre>');
The pattern says find any opening bold tag, followed by zero or more of anything, followed by any closing bold tag and put the stuff in between the tags into an array called $matches.

The

Uis
modifiers tell it to
  • not be greedy and take each tag one-by-one (U modifier),
  • ignore the case of the letters so it would match <b> or <B> (i modifier),
  • and if the text in between the bold tags spans more than one line for some reason, match the newlines as well (s modifier).

Oh yeah, the capturing subpattern is the set of parentheses in between the bold tags.

kadnan

5:37 pm on Jul 15, 2004 (gmt 0)

10+ Year Member



no sorry
i made it bold for message posting only i didnt know it woudnt render the tag here

i will have to search the words like U-UMID then i have to fetch the word which apears after few charactrs and so son

-adnan

coopster

7:21 pm on Jul 17, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I see. Well, just modify the pattern here for starters to get where you want. As you can see, the regular expression here will capture anything between the bold tags, so change the beginning and ending bold tags here to whatever you need to match and test it out.