A
A
Alexander Sharomet2016-11-04 17:33:28
PHP
Alexander Sharomet, 2016-11-04 17:33:28

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;

php which handles this file. I need the data only after the colon.
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 - эти данные и нужно заменить
}

Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander X, 2016-11-09
@sharomet

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 question

Ask a Question

731 491 924 answers to any question