Answer the question
In order to leave comments, you need to log in
How to properly parse a file?
Hello.
I have a file with the following data:
$base-color-primary:#3687ef;
$base-color-second:#fc665e;
$base-color-third:#b143b3;
[
'base-color-primary' => '#3687ef',
'base-color-second' => '#fc665e',
'base-color-third' => '#b143b3'
]
// $data - данные
preg_match_all('/\$(.*)\:/', $data, $arr); // Получаем значение от $ до : , получаем $base-color-primary:
for($v = 0;$v<count($arr[0]);$v++){
$variables[$v] = trim(str_replace(array(':','$'),'',$arr[0][$v])); // Проходим по каждому значению и убираем $ и : , получаем base-color-primary
}
$var = array();
for($v = 0;$v<count($arr[0]);$v++){
$variables[$v] = trim(str_replace(array(':','$'),'',$arr[0][$v]));
}
for($i = 0; $i < count($variables);$i++){
preg_match_all('/\#(.*)\;/', $data, $res);
$var[$variables[$i]] = trim(strtok($res[1][0], ';'));
}
return $var;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question