PHP code example of dlundgren / css-splitter

1. Go to this page and download the library: Download dlundgren/css-splitter library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dlundgren / css-splitter example snippets



$splitter = new \CssSplitter\Splitter();
// Load your css file
$css = file_get_contents('styles.css');

// Skip the first part as the Internet Explorer interprets your css until it reaches the limit
$selector_count = $splitter->countSelectors($css) - 4095;
// Calculate how many additional parts we need to create
$additional_part_count =  ceil($selector_count / 4095);

if($additional_part_count > 0) {
	// Loop and create the additional parts
	// Add an offset of two as we are creating the css from the second part on
	for($part = 2; $part < $additional_part_count + 2; $part++) {
		// Create or update the css files
		file_put_contents('styles_'. $part .'.css', $splitter->split($css, $part));
	}
}