Forum Moderators: coopster

Message Too Old, No Replies

regex assistance :: parsing text file

         

mgm_03

6:33 pm on Mar 9, 2006 (gmt 0)

10+ Year Member



I need to parse a text file that is in the form shown below. However, I only need to get the data from some of the fields...we are only storing some fields in mysql

[id]8935[description]a description goes here[price]8.95[deptID]T[subdeptID]G

What I need is a regex that will identify a certain key (e.g. price) and get the data that follows that key (8.95) . So I need what's between "]" and "["

The data will contain periods and apostrophes

Any suggestions are greatly appreciated.

ChadSEO

7:45 pm on Mar 9, 2006 (gmt 0)

10+ Year Member



mgm_03,

The following worked for me:

$test = '[id]8935[description]a description goes here[price]8.95[deptID]T[subdeptID]G';

if(preg_match('/\[description\]([^\]]+)\[/',$test,$matches)) {
print "Found Description: " . $matches[1] . "\n";
}

Chad