Last active
February 24, 2019 13:33
-
-
Save essamamdani/299a31c01b899c3ca42a66c5266e8df5 to your computer and use it in GitHub Desktop.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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,",")."}"; | |
| } | |
| $inlineCSS = "background-image: url(https://source.unsplash.com/random);font-family:arial;text-align:center;display:block;"; | |
| echo inlineCSStoReact($text); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment