Hi people. 🙂
First of all: Im from germany so please excuse my bad english. 😉
Im sure there was already something slightly familiar, but i couldn't find any thread/help which matches my exact problem. I never used regexp, or neither i do understand it for real.
Here is the code, which contains comments to describe what my problem is and what im trying to do:
# im trying to do a simple(?) bbcode like template system.
# the idea is of having simple tags to do whole forms and html.
#
# after some google searches i came to preg_match_all
# for the job, so i get arrays. simple replace is not
# working tho, because i want to be able to define what to
# replace with my own markup code. flexibility is asked here.
# f.e: [input = input field, "|" seperates attribute values..
# heres a example template look-a-like..
$common_text = "This is text which could come from anywhere <br>"
."and it has not attributes, breaks, or whatsoever.<br>"
."<br>"
."Your nickname: [input|text|user|40|boxes]<br>"
."Your password: [input|password|pass|20|boxes]<br>"
."<br>"
."Now i want a regex, which takes everything between <br>"
."the [ and the ], so i can use the data by doing a explode<br>"
."later on...<br>";
# here i call the parser (which should do the regex and call the replace
# function ..etc.
echo $common_text."<br><br><hr>";
parseTPL($common_text);
//-------------- here we go ---------------
function parseTPL($code)
{
preg_match_all("/\[input.*\]/m",$code,$tplcode); // that should do the job. help here.
print_r($tplcode);
// i expect return values like = "input|text|user|40|boxes" in each array,
// i got it tho, but only for 1 occurence, the second match messed up the first...
// it doesnt stop after the ending "]"
// after the one above is working:
// i have plans to count the occurencies, and spli the data for reassignment
// to the right spot.. with this data i wanna call my replace function, which
// gives the right code back into the stream.
// like [input|text|user|40|boxes] => <input type=text name=user size=40 class=boxes>
// $tplcodedata = explode("|",$tplcode); // here i wanna fetch the attributes.
// print_r($tplcodedata);
// call form($tplcodedata[0],$tplcodedata[1],....)
}
If some regexp god is on this forum i would be glad if you could help me. The code above is working without any errors. You could run it to see the bad sideeffect of the current state (which i would like to have solved as explained).
thanks alot for your time.
regards, mukos.