RE: [PHP] Re: An if statment that someone else designed and I can't parse ;(
| From: | Mike | Date: | Tue, 27 Aug 2002 15:35:43 +0000 |
| Subject: | RE: [PHP] 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-114264@lists.php.net to get a copy of this message | ||
I can't use this because there is some other stuff that is also in %
signs... The whole line is as thus:
$string = "a
href=\"{$_SERVER['PHP_SELF']}?thing=do&id=%number%\">%some%
- %stuff% %if%%artist%?(%artist% Minutes):\"WAH!\"%if%</a>";
So doing an explode on all the % signs would not work unfortunately.
Thanks,
Mike
-----Original Message-----
From: Richard Lynch [mailto:rich@phpbootcamp.com]
Sent: Saturday, August 24, 2002 7:36 PM
To: Mike
Cc: php-general@lists.php.net
Subject: [PHP] Re: An if statment that someone else designed and I can't
parse ;(
>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
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php