Answer the question
In order to leave comments, you need to log in
How to replace data in sass file using php?
Hello.
Please tell me how to replace some data in the file.
The idea is this: I read the file and substitute the value in the form ( <input type="text">
). The user can then change these values and save them with their own. How do I save new user data to a file?
Example
The file itself
$base-text-size: 14px;
$base-bg-color: #fafafa;
$base-text-color: #353535;
preg_match_all('/(.+):(.+)/', file_get_contents('scss/variables.scss'), $matches);
for($i = 0;$i<count($matches[2]);$i++){
print_r($matches[2][$i]); //14px, #fafafa, 353535 - эти данные и нужно заменить
}
Answer the question
In order to leave comments, you need to log in
well so he almost answered :)
only not preg_match, but preg_replace.
well, I would correct the regular expression (add optional spaces, lazy quantifiers and a semicolon):
/\s*(.+?)\s*\:\s*(.+?)\s*\;/
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question