summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: afb3b1a)
raw | patch | inline | side by side (parent: afb3b1a)
author | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Tue, 5 Oct 2010 07:18:50 +0000 (07:18 +0000) | ||
committer | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Tue, 5 Oct 2010 07:18:50 +0000 (07:18 +0000) |
-> use [n-m] instead of {0:3}
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@19914 594d385d-05f5-0310-b6e9-bd551577e9d8
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@19914 594d385d-05f5-0310-b6e9-bd551577e9d8
gosa-core/include/functions.inc | patch | blob | history |
index 59725b1d18216c6952338ff1b3456ade722b06e0..338ab70da6afc6a643082332abee24394e37a9aa 100644 (file)
* '%uid@gonicus.de' Replaces '%uid' with 'uid'.
* '%uid{0}@gonicus.de' Replaces '%uid{0}' with the first char of 'uid'.
* '%uid{2:4}@gonicus.de' Replaces '%uid{2:4}' with three chars from 'uid' starting from the second.
- *
+ *
* @param String The string to perform the action on.
* @param Array An array of replacements.
- * @return The resulting string.
+ * @return The resulting string.
*/
function fillReplacements($str, $attrs, $shellArg = FALSE, $default = "")
{
// Get all matching parts of the given string and sort them by
// length, to avoid replacing strings like '%uidNumber' with 'uid'
// instead of 'uidNumber'; The longest tring at first.
- preg_match_all('/(%([a-z0-9]+)(\{(([0-9]+)(:([0-9]+))?)\})?)/i', $str ,$matches, PREG_SET_ORDER);
+ preg_match_all('/(\{?%([a-z0-9]+)(\[(([0-9]+)(\-([0-9]+))?)\])?\}?)/i', $str ,$matches, PREG_SET_ORDER);
$hits = array();
foreach($matches as $match){
$hits[strlen($match[2]).$match[0]] = $match;
foreach($hits as $match){
// Avoid errors about undefined index.
+ $name = $match[2];
if(!isset($attrs[$name])) $attrs[$name] = $default;
- // Calculate the replacement
- $name = $match[2];
+ // Calculate the replacement
$start = (isset($match[5])) ? $match[5] : 0;
- $end = (isset($match[7])) ? $match[7] : strlen($attrs[$name]);
+ $end = strlen($attrs[$name]);
+ if(isset($match[5]) && !isset($match[7])){
+ $end = 1;
+ }elseif(isset($match[5]) && isset($match[7])){
+ $end = ($match[7]-$start+1);
+ }
$value = substr($attrs[$name], $start, $end);
// Use values which are valid for shell execution?
return($str);
}
-
// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
?>