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 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); Link to comment https://forums.phpfreaks.com/topic/233287-searching-variable-for/#findComment-1199831 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.