Skip to content

Instantly share code, notes, and snippets.

View essamamdani's full-sized avatar
🌗
Working from home

Essa Mamdani essamamdani

🌗
Working from home
View GitHub Profile
@essamamdani
essamamdani / inlineCSStoReact.php
Last active February 24, 2019 13:33
PHP code of simple little tool is intended to help translate plain CSS into the React in-line style specific JSON representation. Making it easy to copy and paste into an inline React component.
function inlineCSStoReact($normalcss){
$json = preg_replace_callback(
"|(\w+)\-?(\w+)?\s*:\s*([^;]+)\s*;?|",
function($matches){
return '"'.$matches[1].ucfirst($matches[2]).'":"'.$matches[3].'",';
},
$normalcss);
return "{".rtrim($json,",")."}";
}