PHPTOM Posted April 10, 2011 Share Posted April 10, 2011 Hey, Looking to find a solution to something. I have been experimenting making a template engine for a website I am building. How can I search a variable for all occurrences of {VARIABLE} eg. {Username} {Title} {Content} so I can str_replace them. Thank you Quote Link to comment https://forums.phpfreaks.com/topic/233287-searching-variable-for/ Share on other sites More sharing options...
.josh Posted April 10, 2011 Share Posted April 10, 2011 $subject = "whatever you are searching"; // this will find all of the items and put into $matches array preg_match_all('~\{([^\}]+)\}~',$subject,$matches); // alternatively, this will find the items and replace them with something $subject = preg_replace('~\{([^\}]+)\}~','replacement here',$string); Quote Link to comment https://forums.phpfreaks.com/topic/233287-searching-variable-for/#findComment-1199831 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.