Jump to content

jtetterton

New Members
  • Posts

    5
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

jtetterton's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. You're a gentleman and a scholar! <?php $message = "EASTRIVANN RES STRUCTURE FIRE AD: 4966 TURKEY SAG RD CTY: AC LOC: ATAC4 FIRE IN STRUCTURE/ALARM CO CONFIRMED W/HOMEOWNER XST: 2751 BELL ACRES XST2: 2312 PETERS MTN RD"; $delimiters = array("EASTRIVANN", "AD:", "CTY:", "LOC:", "XST:", "XST2:"); $replaceWith = "~";//replace the non-bolded text with a tilde character $newMessage = str_replace($delimiters, $replaceWith, $message); //now explode on the ~ character to get all the pieces. $array = explode($replaceWith, $newMessage); echo "Call Type:<br>"; echo $array[1]; echo "<br>Address:<br>"; echo $array[2]; echo "<br>Location:<br>"; echo $array[3]; echo "<br>Cross Street 1:<br>"; echo $array[4]; echo "<br>Cross Street 2:<br>"; echo $array[5]; ?> Thanks so much for the help!
  2. I just noticed there was a REGEX forum, if a moderator could move this, that would be appreciated (I hate it when people double post in multiple forums). Jason
  3. I've highlighted the data to be extracted in bold, the non bolded text will appear in every string. $message = "EASTRIVANN RES STRUCTURE FIRE AD: 4966 TURKEY SAG RD CTY: AC LOC: ATAC4 FIRE IN STRUCTURE/ALARM CO CONFIRMED W/HOMEOWNER XST: 2751 BELL ACRES XST2: 2312 PETERS MTN RD"; So for the first match, I need to know how to tell regex to look for EASTRIVANN as the starting point and AD: as the ending poing and put RES STRUCTURE FIRE into the array. For the second one, look for AD: and CTY: and store 4966 TURKEY SAG RD into the array.
  4. Thanks for the quick reply I only want to match the constant text before and after the data. Here is a few more examples: EASTRIVANN TREE DOWN AD: LOUISA RD&CLOVERFIELDS FARM CTY: AC LOC: AREA OF TREE BLOCKING ROADWAY EASTRIVANN PUBLIC SERVICE CALL AD: 5000 LOUISA RD CTY: AC ASSIST PD AT ACCIDENT SCENE XST: 4410 CLOVERFIELDS FARM XST2: 181 CLOVER HILL FARM EASTRIVANN MVA AD: RICHMOND RD&E I64 EXIT 124 OFF CTY: AC 2 CAR UNK INJ, SLIGHT SMOKE. REAR END COLLISION, RED CRYSLER, EXPIDENTION Each string that I feed into preg_match will have the same format. I was under the impression, with the proper pattern, that I could feed the information into the $matches array and then do with it as I please. I hope this helps. Jason
  5. I'm trying to dissect a string using preg_match but I'm having a hard time understanding the tutorials (and the php manual). This is as far as I've gotten: <?php $message = "EASTRIVANN RES STRUCTURE FIRE AD: 4966 TURKEY SAG RD CTY: AC LOC: ATAC4 FIRE IN STRUCTURE/ALARM CO CONFIRMED W/HOMEOWNER XST: 2751 BELL ACRES XST2: 2312 PETERS MTN RD"; $typepattern = ('/^EASTRIVANN /'); preg_match($typepattern, $message, $matches); if ($matches) { echo $matches[0]; }else{ echo 'No matches.'; } ?> My goal is to pull the following out of the string: $alarmtype = "RES STRUCTURE FIRE"; $address = "4966 TURKEY SAG RD"; $county = "AC"; $location = "ATAC4 FIRE IN STRUCTURE/ALARM CO CONFIRMED W/HOMEOWNER"; $xst = "2751 BELL ACRES"; $xst2 = "2312 PETERS MTN RD"; I am them storing the values into a database for later retrieval. I've gotten as far as Matching EASTRIVANN but i'm not sure how to pull out the actual text between my anchors. Any help would greatly be appreciated Thanks Jason
×
×
  • 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.