解决方案
PHP Live Regex
,这给了我一个更好的工具来计算正则表达式,我改变了
str_replace
到
preg_replace
现在一切似乎都按预期进行。
/**
* Set Sass Variables
*
* @param array $option contains the option object for modifying the SASS
*/
public function set_sass_color($option = array()){
$option['str'] = 'here';
$option_name = 'primary-color';
$search = '/('.$option_name.')[:](.*?)[;]/';
$variables = file_get_contents(get_template_directory().'/assets/styles/common/_variables.scss');
$variables_after = preg_replace($search,$option['str'],$variables);
return $variables_after;
}