Skip to content

Instantly share code, notes, and snippets.

@codingfox-rus
Last active February 6, 2018 12:11
Show Gist options
  • Save codingfox-rus/31cf64182cdba5d95bdee20667a90186 to your computer and use it in GitHub Desktop.
Save codingfox-rus/31cf64182cdba5d95bdee20667a90186 to your computer and use it in GitHub Desktop.
Фикс при переводе дока из Google Docs в Html, для сохранения в БД через визуальный редактор (он режет некоторые теги)
<?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