stuartmarsh Posted November 10, 2008 Share Posted November 10, 2008 Hi all, Could someone please supply me with a regex that I can use with preg_match_all to find all strings between {$ and }? Example: Test String: Some {$example} text Match: example I want to use this in a templating engine so I can replace all matches with the appropriate variable. Cheers Quote Link to comment Share on other sites More sharing options...
DarkWater Posted November 10, 2008 Share Posted November 10, 2008 You could just use str_replace() for that, unless you're like, adding modifiers and stuff like Smarty does. Quote Link to comment Share on other sites More sharing options...
stuartmarsh Posted November 10, 2008 Author Share Posted November 10, 2008 Yea I plan to implement it in a way like Smarty. Developers will be able to assign their own content to template variables, i.e. {$menu}, {$content}, {$function()}, etc. Quote Link to comment Share on other sites More sharing options...
ddrudik Posted November 10, 2008 Share Posted November 10, 2008 function repfunc($match){ // do something with $match[1] // return something effectively replacing $match[0] } $out=preg_replace_callback('/\{(\$[^}]*)\}/','repfunc',$in); Quote Link to comment Share on other sites More sharing options...
stuartmarsh Posted November 10, 2008 Author Share Posted November 10, 2008 This should do very nicely. Thank you! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.