Forum Moderators: coopster

Message Too Old, No Replies

Checking a string for symbols

         

Furutsuzeru

11:17 pm on Aug 8, 2008 (gmt 0)

10+ Year Member



Hello, I am trying to build a template system for a software, though I fear the process is going to be more difficult than I expected it to be in the beginning.

I am looking for a way on getting the locating a string that is surrounded by {}, and then be able to extract the contents in between the brackets. An example would be:

{index}

I would then I would be able to extract index from the {index} string. Although, I have tried looking through preg_match(), eregi() and those type of functions, though I have no idea what would be the best way to have this done. Any ideas?

[edited by: Furutsuzeru at 11:53 pm (utc) on Aug. 8, 2008]

wesg

4:02 am on Aug 9, 2008 (gmt 0)

10+ Year Member



Preg_match or preg_match_all is your best bet.

To match all text between {} try using this as your regular expression:

/{(.*)}/

The text between {} would be sent to the array you specify.

Give that a try, and let us know where we can help.

Furutsuzeru

4:42 pm on Aug 13, 2008 (gmt 0)

10+ Year Member



I'm sorry. Ah, yes, it works. I'll have to change that regular expression though. Those wildcards look a bit dangerous, since a user can easily type {'} inside of the brackets.

Thanks for the basic concept, by the way.