Skip to content

Instantly share code, notes, and snippets.

@ibnux
Created April 23, 2020 09:27
Show Gist options
  • Save ibnux/aa4ddb1adbf3545a0c8953c020bc5aa9 to your computer and use it in GitHub Desktop.
Save ibnux/aa4ddb1adbf3545a0c8953c020bc5aa9 to your computer and use it in GitHub Desktop.
PHP Script to scan CSS class in folder, it will create json array you can use to strip unused css
<?php
$class = array();
$path = "template/";
cariFile($path);
print_r($class);
file_put_contents("css_class.json",json_encode($class,JSON_PRETTY_PRINT));
//class="
function cariFile($path){
$list = scandir($path);
foreach($list as $file){
if(!in_array($file,['.','..'])){
if(is_dir($path.$file)){
cariFile($path.$file."/");
}else{
$isi = file_get_contents($path.$file);
while(strpos($isi,'class="')!==false){
$tmp = substr($isi,strpos($isi,'class="')+7);
$css = substr($tmp,0,strpos($tmp,'"'));
parsingCSS($css);
$isi = $tmp;
}
}
}
}
}
function parsingCSS($css){
global $class;
$css = explode(" ",$css);
$class = array_merge($class,$css);
$class = array_unique(array_filter($class));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment