khanat-opennel-code/code/web/public_php/admin/smarty/plugins/function.substr.php
Guillaume Dupuy 6f1197d633 Allow target to work with sheetName and a quiet option
HG : Enter commit message.  Lines beginning with 'HG:' are removed.
2016-11-28 00:54:33 +01:00

55 lines
No EOL
1.2 KiB
PHP

<?php
/*
*
* usage: {substr src="plop" start="0" length="4" delim="/"}
*
*/
function smarty_function_substr($params, &$smarty)
{
if (!isset($params['src'])) {
$smarty->trigger_error("substr: missing 'src' parameter");
return;
}
if (!isset($params['var'])) {
$smarty->trigger_error("substr: missing 'var' parameter");
return;
}
$tmp = "";
if (isset($params['start']) && isset($params['length']))
{
$tmp = substr($params['src'], $params['start'], $params['length']);
}
elseif (isset($params['start']) && isset($params['delim']))
{
$tmp = substr($params['src'], $params['start'], strpos($params['src'], $params['delim']));
}
elseif (isset($params['delim']))
{
$tmp = substr($params['src'], strpos($params['src'], $params['delim']));
}
elseif (isset($params['start']))
{
$tmp = substr($params['src'], $params['start']);
}
elseif (isset($params['length']))
{
$tmp = substr($params['src'], 0, $params['length']);
}
else
{
$smarty->trigger_error("substr: missing start/stop/delim parameters");
return;
}
$smarty->assign($params['var'], $tmp);
}
?>