fork download
  1. <?php
  2.  
  3. // your code goes here
  4.  
  5. $input = "
  6. /** preloader colors **/
  7. @preloader_bg: #0081ff;
  8. @preloader_color: #fff;
  9.  
  10. /** layout **/
  11. @body_bg_image_position: ~'left top';
  12. @body_bg_image_repeat: ~'no-repeat';
  13. @body_bg_image_cover: ~'auto';
  14. @body_bg_image: ~'';
  15. ";
  16.  
  17. // create an array to store the values
  18. $cssVar = [];
  19.  
  20. // iterate over the lines
  21. foreach (split("\n", $input) as $ln) {
  22. // ignore lines that don't start with @ as they are not variables
  23. if ($ln[0] != "@") {
  24. continue;
  25. }
  26. // get the key and value for the css variable
  27. $bits = explode(":", $ln);
  28. $key = substr(trim($bits[0]), 1);
  29. $value = trim($bits[1]);
  30.  
  31. // store the value
  32. $cssVar[$key] = $value;
  33. }
  34.  
  35. var_export($cssVar);
Success #stdin #stdout #stderr 0.01s 52488KB
stdin
Standard input is empty
stdout
array (
  'preloader_bg' => '#0081ff;',
  'preloader_color' => '#fff;',
  'body_bg_image_position' => '~\'left top\';',
  'body_bg_image_repeat' => '~\'no-repeat\';',
  'body_bg_image_cover' => '~\'auto\';',
  'body_bg_image' => '~\'\';',
)
stderr
PHP Notice:  Uninitialized string offset: 0 in /home/r2Es9M/prog.php on line 23
PHP Notice:  Uninitialized string offset: 0 in /home/r2Es9M/prog.php on line 23
PHP Notice:  Uninitialized string offset: 0 in /home/r2Es9M/prog.php on line 23