Forum Moderators: coopster

Message Too Old, No Replies

preg_match : matching a template marker

for a template system

         

Anyango

6:27 pm on Dec 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yo Folks!

Merry Christmas

in our template system, we use, as all others do, some markers which while compilation of code for user get replaced by their values. for example

<title>#TITLE#</title>

while php parser would parse that html content to prepare its output for user. our code will replace #TITLE# with the value of title it got from the db, right no problem with that.

Now, we want to be able to make a marker like string that works like a function for example would like to have a marker like this

#CATEGORY[Sports]#

#LIST[Cars]#

just need a simple algo using preg_match or anything that would do this

input: #CATEGORY[Sports]#
output: function=CATEGORY
parameter=Sports

input: #LIST[Cars]#
output: function=LIST
parameter=Cars

someone could assist me in writting regular expression for that? please note that only the format of input would be pre-known. Name of the function and parameter cant be hard coded.

Please leme know if there is something that needs explanation

Ciao

jc_armor

12:48 am on Dec 27, 2005 (gmt 0)

10+ Year Member



try this one:

#(.*)\[(.*)\]#

Anyango

2:09 pm on Dec 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Perfect!

Works like a charm. Thanks budd. thanks alot

jc_armor

11:38 pm on Dec 27, 2005 (gmt 0)

10+ Year Member



glad to be of help :)