Connecting Tech Pros Worldwide Forums | Help | Site Map

pattern matching in php

Newbie
 
Join Date: May 2007
Posts: 18
#1: Aug 23 '07
hi, everyone

I have the following line in a file

TWS - Maestro Infrastructure,METINTSV50601#TWSFIXCLUOFF.TWS_CLU_ OFF:1011,MGR:some (name) Kathryn,AD:some name

i am using php to some part of the file for example
server name:METINTSV50601
jobname:TWSFIXCLUOFF
schedulename:TWS_CLU_OFF
abend#:1011

Does anyone know a routine to get these string from the line in PHP thank you.

pbmods's Avatar
Site Moderator
 
Join Date: Apr 2007
Location: Texas
Posts: 5,435
#2: Aug 23 '07

re: pattern matching in php


Heya, Jean.
Quote:

Originally Posted by jjeanj1

TWS - Maestro Infrastructure,METINTSV50601#TWSFIXCLUOFF.TWS_CLU_ OFF:1011,MGR:Sbarbaro (Pinto) Kathryn,AD:Trovello Andrea

i am using php to some part of the file for example
server name:METINTSV50601
jobname:TWSFIXCLUOFF
schedulename:TWS_CLU_OFF
abend#:1011

So there's a bunch of characters that we don't care about,
followed by a comma,
followed by a bunch of characters that we do care about (server name),
followed by a pound,
followed by some more characters that we care about (jobname),
followed by a period,
followed by some more characters that we care about (schedulename),
followed by a colon,
followed by some numbers that we care about (abend#),
terminated by a comma.

We can use a regular expression to describe this string:
Expand|Select|Wrap|Line Numbers
  1. $matches = array();
  2. preg_match('/,(.+?)#(.+?)\\.(.+?):(\\d+?),/', $string, $matches);
  3.  
  4. print_r($matches);
  5.  
That should get you started. For more info on regular expressions, check out this article.
Newbie
 
Join Date: May 2007
Posts: 18
#3: Aug 23 '07

re: pattern matching in php


hi i tried what you have on there and it does not work. I am not really sure why.

i get Array()
Newbie
 
Join Date: May 2007
Posts: 18
#4: Aug 23 '07

re: pattern matching in php


Sorry about that pbmods. Everything works great thank you so much for your help. I LOVE THIS SITE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
pbmods's Avatar
Site Moderator
 
Join Date: Apr 2007
Location: Texas
Posts: 5,435
#5: Aug 23 '07

re: pattern matching in php


Heya, Jean.

Glad to hear you got it working! Good luck with your project, and if you ever need anything, post back anytime :)
Reply