$val = preg_replace("/\[([^\[\]]*)\]/eis", "'.'.str_replace('$','\$','\\1')", $val); 5
preg_replace换成preg_replace_callback应该怎么换functionget_val($val){if(strrpos($val,'[')!==...
preg_replace换成preg_replace_callback应该怎么换
function get_val($val)
{
if (strrpos($val, '[') !== false)
{
// $val = preg_replace("/\[([^\[\]]*)\]/eis", "'.'.str_replace('$','\$','\\1')", $val);
$val = preg_replace_callback("/\[([^\[\]]*)\]/eis", function($m){ return str_replace('$','\$',$m)}, $val);
}
}
if (strrpos($val, '|') !== false)
{
$moddb = explode('|', $val);
$val = array_shift($moddb);
}
if (empty($val))
{
return '';
}
if (strpos($val, '.$') !== false)
{
$all = explode('.$', $val);
foreach ($all AS $key => $val)
{
$all[$key] = $key == 0 ? $this->make_var($val) : '['. $this->make_var($val) . ']';
}
$p = implode('', $all);
}
else
{
$p = $this->make_var($val);
}
if (!empty($moddb))
{
foreach ($moddb AS $key => $mod)
{
$s = explode(':', $mod);
switch ($s[0])
{
case 'escape':
$s[1] = trim($s[1], '"');
if ($s[1] == 'html')
{
$p = 'htmlspecialchars(' . $p . ')';
}
elseif ($s[1] == 'url')
{
$p = 'urlencode(' . $p . ')';
} 展开
function get_val($val)
{
if (strrpos($val, '[') !== false)
{
// $val = preg_replace("/\[([^\[\]]*)\]/eis", "'.'.str_replace('$','\$','\\1')", $val);
$val = preg_replace_callback("/\[([^\[\]]*)\]/eis", function($m){ return str_replace('$','\$',$m)}, $val);
}
}
if (strrpos($val, '|') !== false)
{
$moddb = explode('|', $val);
$val = array_shift($moddb);
}
if (empty($val))
{
return '';
}
if (strpos($val, '.$') !== false)
{
$all = explode('.$', $val);
foreach ($all AS $key => $val)
{
$all[$key] = $key == 0 ? $this->make_var($val) : '['. $this->make_var($val) . ']';
}
$p = implode('', $all);
}
else
{
$p = $this->make_var($val);
}
if (!empty($moddb))
{
foreach ($moddb AS $key => $mod)
{
$s = explode(':', $mod);
switch ($s[0])
{
case 'escape':
$s[1] = trim($s[1], '"');
if ($s[1] == 'html')
{
$p = 'htmlspecialchars(' . $p . ')';
}
elseif ($s[1] == 'url')
{
$p = 'urlencode(' . $p . ')';
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询