Last active
February 6, 2018 12:11
-
-
Save codingfox-rus/31cf64182cdba5d95bdee20667a90186 to your computer and use it in GitHub Desktop.
Фикс при переводе дока из Google Docs в Html, для сохранения в БД через визуальный редактор (он режет некоторые теги)
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
<?php | |
$html = file_get_contents('index.html'); | |
$cssPattern = '/\.(c[0-9]+)\{(.*)\}/U'; | |
preg_match_all($cssPattern, $html, $cssMatches, PREG_SET_ORDER); | |
$classPattern = '/\sclass=\"([A-Za-z0-9\s]+)\"/U'; | |
preg_match_all($classPattern, $html, $classMatches, PREG_SET_ORDER); | |
foreach ($classMatches as $clMatch){ | |
$cls = $clMatch[1]; | |
$classes = explode(" ", $cls); | |
$allStyles = ''; | |
foreach ($classes as $cl){ | |
foreach ($cssMatches as $csMatch){ | |
$cssClassName = $csMatch[1]; | |
if ($cl == $cssClassName){ | |
$style = $csMatch[2]; | |
if (strpos($style, ';') === false){ | |
$style .= ';'; | |
} | |
$allStyles .= $style; | |
} | |
} | |
} | |
$htmlPattern = '/\sclass=\"'. $cls .'\"/'; | |
$styles = ' style="'. $allStyles .'"'; | |
$html = preg_replace($htmlPattern, $styles, $html); | |
} | |
preg_match('/\<body[^>]+>(.*)\<\/body>/', $html, $body); | |
$html = $body[1]; | |
//print_r($body[1]); | |
file_put_contents('index.html', $html); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment