StrangeWill Posted January 5, 2007 Share Posted January 5, 2007 Okay so I have a string:"This is a {today.weather} day"We can replace {today.weather} with $this->$Strings['today']['weather'] then use eval? Right?Except the string may include "{" or ";" which seems to confuse the hell out of eval.Example:'<p style="font-size:28px;">This is a {today.weather} day</p>'Any ideas on how to overcome this problem efficiently? Wouldn't it be extremely time consuming to loop through every instance of {var.var} (gather them using regex) and then do a replace one by one? Link to comment https://forums.phpfreaks.com/topic/32911-process-data-in-a-string/ Share on other sites More sharing options...
trq Posted January 5, 2007 Share Posted January 5, 2007 [quote]We can replace {today.weather} with $this->$Strings['today']['weather'] then use eval? Right?[/quote]How? eval doesnt replace anything, it evaluates a string as if it where php. If this...[code=php:0]'<p style="font-size:28px;">This is a {today.weather} day</p>'[/code]is your string, I don't see what good eval() would be. Link to comment https://forums.phpfreaks.com/topic/32911-process-data-in-a-string/#findComment-153225 Share on other sites More sharing options...
Barand Posted January 5, 2007 Share Posted January 5, 2007 Have a look at http://www.php.net/str_replace Link to comment https://forums.phpfreaks.com/topic/32911-process-data-in-a-string/#findComment-153237 Share on other sites More sharing options...
StrangeWill Posted January 8, 2007 Author Share Posted January 8, 2007 [quote author=thorpe link=topic=121057.msg497155#msg497155 date=1167959661][quote]We can replace {today.weather} with $this->$Strings['today']['weather'] then use eval? Right?[/quote]How? eval doesnt replace anything, it evaluates a string as if it where php. If this...[code=php:0]'<p style="font-size:28px;">This is a {today.weather} day</p>'[/code]is your string, I don't see what good eval() would be.[/quote]Well what I'd do is replace {today.weather} with $this->Strings['today']['weather'] than eval that, but that doesn't work.[quote author=Barand link=topic=121057.msg497167#msg497167 date=1167960748]Have a look at http://www.php.net/str_replace[/quote]Okay, so what you're saying is I should use regex to get all occurrences of {val.val} in my string, then build that into an array, and do a replace?I would think that to be EXTREMELY slow, but if that wouldn't be the case, then thanks. :)So like:Regex->Get all "{(*.).(*.)}"Split all (if needed) to get the two separate valsdo(while there are values to process){replace($original regex val, $this->$Strings[$RegexSplit[0],$RegexSplit[1]]);}??Basically I'm building a small (but QUICK) template engine, thats why I'm trying to keep load times small, and need it to process lots of info. Link to comment https://forums.phpfreaks.com/topic/32911-process-data-in-a-string/#findComment-156018 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.