?? template.php
字號:
} /****************************************************************************** * This functions sets the value of a variable. * * It may be called with either a varname and a value as two strings or an * an associative array with the key being the varname and the value being * the new variable value. * * The function inserts the new value of the variable into the $varkeys and * $varvals hashes. It is not necessary for a variable to exist in these hashes * before calling this function. * * An optional third parameter allows the value for each varname to be appended * to the existing variable instead of replacing it. The default is to replace. * This feature was introduced after the 7.2d release. * * * usage: set_var(string $varname, [string $value = ""], [boolean $append = false]) * or * usage: set_var(array $varname = (string $varname => string $value), [mixed $dummy_var], [boolean $append = false]) * * @param $varname either a string containing a varname or a hash of varname/value pairs. * @param $value if $varname is a string this contains the new value for the variable otherwise this parameter is ignored * @param $append if true, the value is appended to the variable's existing value * @access public * @return void */ function set_var($varname, $value = "", $append = false) { if (!is_array($varname)) { if (!empty($varname)) { if ($this->debug & 1) { printf("<b>set_var:</b> (with scalar) <b>%s</b> = '%s'<br>\n", $varname, htmlentities($value)); } $this->varkeys[$varname] = "/".$this->varname($varname)."/"; if ($append && isset($this->varvals[$varname])) { $this->varvals[$varname] .= $value; } else { $this->varvals[$varname] = $value; } } } else { reset($varname); while(list($k, $v) = each($varname)) { if (!empty($k)) { if ($this->debug & 1) { printf("<b>set_var:</b> (with array) <b>%s</b> = '%s'<br>\n", $k, htmlentities($v)); } $this->varkeys[$k] = "/".$this->varname($k)."/"; if ($append && isset($this->varvals[$k])) { $this->varvals[$k] .= $v; } else { $this->varvals[$k] = $v; } } } } } /****************************************************************************** * This functions clears the value of a variable. * * It may be called with either a varname as a string or an array with the * values being the varnames to be cleared. * * The function sets the value of the variable in the $varkeys and $varvals * hashes to "". It is not necessary for a variable to exist in these hashes * before calling this function. * * * usage: clear_var(string $varname) * or * usage: clear_var(array $varname = (string $varname)) * * @param $varname either a string containing a varname or an array of varnames. * @access public * @return void */ function clear_var($varname) { if (!is_array($varname)) { if (!empty($varname)) { if ($this->debug & 1) { printf("<b>clear_var:</b> (with scalar) <b>%s</b><br>\n", $varname); } $this->set_var($varname, ""); } } else { reset($varname); while(list($k, $v) = each($varname)) { if (!empty($v)) { if ($this->debug & 1) { printf("<b>clear_var:</b> (with array) <b>%s</b><br>\n", $v); } $this->set_var($v, ""); } } } } /****************************************************************************** * This functions unsets a variable completely. * * It may be called with either a varname as a string or an array with the * values being the varnames to be cleared. * * The function removes the variable from the $varkeys and $varvals hashes. * It is not necessary for a variable to exist in these hashes before calling * this function. * * * usage: unset_var(string $varname) * or * usage: unset_var(array $varname = (string $varname)) * * @param $varname either a string containing a varname or an array of varnames. * @access public * @return void */ function unset_var($varname) { if (!is_array($varname)) { if (!empty($varname)) { if ($this->debug & 1) { printf("<b>unset_var:</b> (with scalar) <b>%s</b><br>\n", $varname); } unset($this->varkeys[$varname]); unset($this->varvals[$varname]); } } else { reset($varname); while(list($k, $v) = each($varname)) { if (!empty($v)) { if ($this->debug & 1) { printf("<b>unset_var:</b> (with array) <b>%s</b><br>\n", $v); } unset($this->varkeys[$v]); unset($this->varvals[$v]); } } } } /****************************************************************************** * This function fills in all the variables contained within the variable named * $varname. The resulting value is returned as the function result and the * original value of the variable varname is not changed. The resulting string * is not "finished", that is, the unresolved variable name policy has not been * applied yet. * * Returns: the value of the variable $varname with all variables substituted. * * usage: subst(string $varname) * * @param $varname the name of the variable within which variables are to be substituted * @access public * @return string */ function subst($varname) { $varvals_quoted = array(); if ($this->debug & 4) { echo "<p><b>subst:</b> varname = $varname</p>\n"; } if (!$this->loadfile($varname)) { $this->halt("subst: unable to load $varname."); return false; } // quote the replacement strings to prevent bogus stripping of special chars reset($this->varvals); while(list($k, $v) = each($this->varvals)) { $varvals_quoted[$k] = preg_replace(array('/\\\\/', '/\$/'), array('\\\\\\\\', '\\\\$'), $v); } $str = $this->get_var($varname); $str = preg_replace($this->varkeys, $varvals_quoted, $str); return $str; } /****************************************************************************** * This is shorthand for print $this->subst($varname). See subst for further * details. * * Returns: always returns false. * * usage: psubst(string $varname) * * @param $varname the name of the variable within which variables are to be substituted * @access public * @return false * @see subst */ function psubst($varname) { if ($this->debug & 4) { echo "<p><b>psubst:</b> varname = $varname</p>\n"; } print $this->subst($varname); return false; } /****************************************************************************** * The function substitutes the values of all defined variables in the variable * named $varname and stores or appends the result in the variable named $target. * * It may be called with either a target and a varname as two strings or a * target as a string and an array of variable names in varname. * * The function inserts the new value of the variable into the $varkeys and * $varvals hashes. It is not necessary for a variable to exist in these hashes * before calling this function. * * An optional third parameter allows the value for each varname to be appended * to the existing target variable instead of replacing it. The default is to * replace. * * If $target and $varname are both strings, the substituted value of the * variable $varname is inserted into or appended to $target. * * If $handle is an array of variable names the variables named by $handle are * sequentially substituted and the result of each substitution step is * inserted into or appended to in $target. The resulting substitution is * available in the variable named by $target, as is each intermediate step * for the next $varname in sequence. Note that while it is possible, it * is only rarely desirable to call this function with an array of varnames * and with $append = true. This append feature was introduced after the 7.2d * release. * * Returns: the last value assigned to $target. * * usage: parse(string $target, string $varname, [boolean $append]) * or * usage: parse(string $target, array $varname = (string $varname), [boolean $append]) * * @param $target a string containing the name of the variable into which substituted $varnames are to be stored * @param $varname if a string, the name the name of the variable to substitute or if an array a list of variables to be substituted * @param $append if true, the substituted variables are appended to $target otherwise the existing value of $target is replaced * @access public * @return string * @see subst */ function parse($target, $varname, $append = false) { if (!is_array($varname)) { if ($this->debug & 4) { echo "<p><b>parse:</b> (with scalar) target = $target, varname = $varname, append = $append</p>\n"; } $str = $this->subst($varname); if ($append) { $this->set_var($target, $this->get_var($target) . $str); } else { $this->set_var($target, $str); } } else { reset($varname); while(list($i, $v) = each($varname)) { if ($this->debug & 4) { echo "<p><b>parse:</b> (with array) target = $target, i = $i, varname = $v, append = $append</p>\n"; } $str = $this->subst($v); if ($append) { $this->set_var($target, $this->get_var($target) . $str); } else { $this->set_var($target, $str); } } } if ($this->debug & 4) { echo "<p><b>parse:</b> completed</p>\n"; } return $str; } /****************************************************************************** * This is shorthand for print $this->parse(...) and is functionally identical. * See parse for further details. * * Returns: always returns false. * * usage: pparse(string $target, string $varname, [boolean $append]) * or * usage: pparse(string $target, array $varname = (string $varname), [boolean $append]) * * @param $target a string containing the name of the variable into which substituted $varnames are to be stored * @param $varname if a string, the name the name of the variable to substitute or if an array a list of variables to be substituted * @param $append if true, the substituted variables are appended to $target otherwise the existing value of $target is replaced * @access public * @return false * @see parse */ function pparse($target, $varname, $append = false) { if ($this->debug & 4) { echo "<p><b>pparse:</b> passing parameters to parse...</p>\n"; } print $this->finish($this->parse($target, $varname, $append)); return false; } /****************************************************************************** * This function returns an associative array of all defined variables with the * name as the key and the value of the variable as the value. * * This is mostly useful for debugging. Also note that $this->debug can be used * to echo all variable assignments as they occur and to trace execution. * * Returns: a hash of all defined variable values keyed by their names. * * usage: get_vars() * * @access public * @return array * @see $debug */ function get_vars() { if ($this->debug & 4) { echo "<p><b>get_vars:</b> constructing array of vars...</p>\n";
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -