|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2002-12-30 10:56 UTC] tit dot petric at telemach dot net
[2002-12-30 15:35 UTC] black@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Mon Mar 30 03:00:01 2026 UTC |
i have a template engine running, in it a string (content hereon) with keys and an array (parsevals hereon) with key/values that need to be replaced in the content this is what i do: foreach ($this->_parsevals as $key=>$val) { $retval = str_replace('{'.$key.'}',$val,$retval); } after that i do a preg_match_all to find all the remaining keys in the content with this regexp: '/\{[A-Za-z][-_A-Za-z0-9]*\}/', and find existing keys, which also exist in $this->_parsevals.. if (preg_match_all($this->regex_var,$retval,$result)) { foreach ($result[0] as $val) { $key = substr($val,1,-1); if (isset($this->_parsevals[$key])) { condor_assert($key." exists in parsevals?!?!?"); $retval = str_replace($val, $this->_parsevals[$key],$retval); } } } condor_assert is a basic log function, and its activated with that error message in there... another str_replace seems to solve the problem of the "undefined variable" case.. i tried to reproduce this in a short-self-contained script but failed, i will test it on 4.3 asap