Bootstrap

"Sleek, intuitive, and powerful mobile first front-end framework for faster and easier web development."

It's one of, if not the most popular front-end frameworks in the world. Unfortunately,  without a compatible compiler, php developers haven't been able unleash Bootstrap's full potential.

Less.php was built from the ground-up to work as closely as possible to the only officially supported Bootstrap compiler: less.js.  As such, Less.php can be used to compile Bootstrap's uncompiled source code (LESS files) to produce usable CSS files.  The difference between the CSS generated by less.php and less.js is negligable.  Out of nearly 6,000 lines of CSS, there are a total of 29 lines that aren't exactly the same.  Most of these 29 differences are inconsequential: width: 16.666666666666664%; vs width: 16.66666666666666%;. Here's a complete line-by-line comparison with the CSS generated by less.js on the left and the CSS generated by less.php on the right.

Compiling Bootstrap with Less.php

Download less.php

<?php
require 'less.php/Cache.php';
Less_Cache::$cache_dir = '/var/www/mysite/writable_folder';

$files = array();
$files['/var/www/mysite/bootstrap/bootstrap.less'] = '/mysite/bootstrap/';
$files['/var/www/mysite/custom/my.less'] = '/mysite/custom/';

$css_file_name = Less_Cache::Get( $files );
echo '<link rel="stylesheet" type="text/css" href="/mysite/writable_folder/'.$css_file_name.'">';

 

In this example, the Less_Cache class will compile the bootstrap.less file and save the resulting CSS in /var/www/mysite/writable_folder/.