Re: An if statment that someone else designed and I can't parse ;(

From: Date: Sat, 24 Aug 2002 23:36:03 +0000
Subject: Re: An if statment that someone else designed and I can't parse ;(
Groups: php.general 
Request: Send a blank email to php-general+get-114003@lists.php.net to get a copy of this message
>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%" Personally, I think Regex is (A) overkill and (B) over-complicated. But I'm not very smart. :-) I would do: <?php $string = "%if%(%value%)?(%value%>Minutes):\"WAH!\"%if%"; $parts = explode('%', $string); # That gets you pretty close: # array(0=>if,1=>(,2=>value,3=>)?(,4=>value,5=>>Minutes):"WAH!",6=>if) /* I suspect that there are more %'s in your input, and you might be "finished" at this point... If not, use explode some more: */ $minuteswah = $parts[5]; $minuteswah = explode('):', $minuteswah); ?> Basically, a couple explode calls over the headache of trying to understand some convoluted Regex is always a "win" in my book. :-) http://php.net/explode -- Like Music? http://l-i-e.com/artists.htm

« previous php.general (#114003) next »