An if statment that someone else designed and I can't parse ;(
| From: | Mike | Date: | Fri, 23 Aug 2002 14:12:18 +0000 |
| Subject: | An if statment that someone else designed and I can't parse ;( | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-113768@lists.php.net to get a copy of this message | ||
Hello all,
This may not be the best place to post this question, but I don't know
where else to ask it, so here it goes.
I have a program that someone was helping me to build and one of the
functions returns a string similar to this: "%if%(%value%)?(%value%
Minutes):\"WAH!\"%if%" I don't have any control on the string that is
spits out and I can't edit the program that was built (because the
person that I was working with got in a bad accident and is basically a
vegetable now) but I have to break it out into an array similar to this:
array { 1 => if 2 => value 3 => ( 4 => value 5 => Minutes) 6 =>
"WAH!" 7 => if } I had a regex working for it, but it broke, maybe I
have the syntax for the regex wrong or something, here is the regex:
$RegExPattern = "/(.*)". // First part of the string
"%([^A-Z]{1,3})%". // if
"\(%([^A-Z]{1,10})%\)". // Variable
"(\D{0,1})". // ?
"(.*)". // Whatever is before the
variable (if applicable)
"%([a-z]{1,3})%". // Variable
"((.*):". // Rest of true statement
"(.*))".
"%([a-z]{1,3})%". // if
"(.*)/i"; // rest of string
I also need it to be more robust than what I have right now, it needs to
be able to parse the above statement, but not break if I don't have a
%value% after the question mark and if there is one after the colon, but
I don't know how to do the conditional statements. The array could have
more than 7 values but I need all the stuff out of the %% in it's own
array index (I don't know if index is the right word but I basically
need the stuff in the %% to be in it's own array part (i.e. $array[1])).
Any help at all would be much appreciated, I have looked both on the php
website and any other regex places that I could find on google and they
are all confusing to me.
Thank You,
Mike
funyon@funyon.com
mmacrae@wwnet.net