SassScriptParser::interpolate PHP Method

interpolate() public method

Replace interpolated SassScript contained in '#{}' with the parsed value.
public interpolate ( string $string, SassContext $context ) : string
$string string the text to interpolate
$context SassContext the context in which the string is interpolated
return string the interpolated text
    public function interpolate($string, $context)
    {
        for ($i = 0, $n = preg_match_all(self::MATCH_INTERPOLATION, $string, $matches); $i < $n; $i++) {
            $var = $this->evaluate($matches[1][$i], $context);
            if ($var instanceof SassString) {
                $var = $var->value;
            } else {
                $var = $var->toString();
            }
            if (preg_match('/^unquote\\((["\'])(.*)\\1\\)$/', $var, $match)) {
                $val = $match[2];
            } elseif ($var == '""') {
                $val = "";
            } elseif (preg_match('/^(["\'])(.*)\\1$/', $var, $match)) {
                $val = $match[2];
            } else {
                $val = $var;
            }
            $matches[1][$i] = $val;
        }
        return str_replace($matches[0], $matches[1], $string);
    }