Regular expressions is just not my thing. :(
I have a string that may contain multiple sub strings such as:
[var1="111" var2="222" var3="222" var4="444"]
I basically need to replace each occurrence with the the results of a function that gets each variable.
$string = '[var1="111" var2="222" var3="333" var4="444"]';
$regex = 'var1="(.*)" var2="(.*)" var3="(.*)" var4="(.*)"';
function doit($matches){
return "<strong>".implode(", ", $matches) ."</strong>";
}
echo preg_replace_callback($regex,'doit',$string);
I’m expecting 111, 222, 333, 444.
But I’m not feeling the love. Any help would be appreciated!
Edit: some clarification..
I was simplifying for the sake of the question.
the "vars" will not really be called "var1", "var2" more like [recID="22" template="theName" option="some value", type="list"]
the call back would be more complicated then my simple implode... I would use "id" and connect to a database, get the records and insert them into the template... Hence the need for the call back...
matched values could be almost anything, not just numbers.