1# lessphp v0.3.9 2### <http://leafo.net/lessphp> 3 4[![Build Status](https://secure.travis-ci.org/leafo/lessphp.png)](http://travis-ci.org/leafo/lessphp) 5 6`lessphp` is a compiler for LESS written in PHP. The documentation is great, 7so check it out: <http://leafo.net/lessphp/docs/>. 8 9Here's a quick tutorial: 10 11### How to use in your PHP project 12 13The only file required is `lessc.inc.php`, so copy that to your include directory. 14 15The typical flow of **lessphp** is to create a new instance of `lessc`, 16configure it how you like, then tell it to compile something using one built in 17compile methods. 18 19The `compile` method compiles a string of LESS code to CSS. 20 21```php 22<?php 23require "lessc.inc.php"; 24 25$less = new lessc; 26echo $less->compile(".block { padding: 3 + 4px }"); 27``` 28 29The `compileFile` method reads and compiles a file. It will either return the 30result or write it to the path specified by an optional second argument. 31 32```php 33<?php 34echo $less->compileFile("input.less"); 35``` 36 37The `compileChecked` method is like `compileFile`, but it only compiles if the output 38file doesn't exist or it's older than the input file: 39 40```php 41<?php 42$less->checkedCompile("input.less", "output.css"); 43``` 44 45If there any problem compiling your code, an exception is thrown with a helpful message: 46 47```php 48<?php 49try { 50 $less->compile("invalid LESS } {"); 51} catch (exception $e) { 52 echo "fatal error: " . $e->getMessage(); 53} 54``` 55 56The `lessc` object can be configured through an assortment of instance methods. 57Some possible configuration options include [changing the output format][1], 58[setting variables from PHP][2], and [controlling the preservation of 59comments][3], writing [custom functions][4] and much more. It's all described 60in [the documentation][0]. 61 62 63 [0]: http://leafo.net/lessphp/docs/ 64 [1]: http://leafo.net/lessphp/docs/#output_formatting 65 [2]: http://leafo.net/lessphp/docs/#setting_variables_from_php 66 [3]: http://leafo.net/lessphp/docs/#preserving_comments 67 [4]: http://leafo.net/lessphp/docs/#custom_functions 68 69 70### How to use from the command line 71 72An additional script has been included to use the compiler from the command 73line. In the simplest invocation, you specify an input file and the compiled 74css is written to standard out: 75 76 $ plessc input.less > output.css 77 78Using the -r flag, you can specify LESS code directly as an argument or, if 79the argument is left off, from standard in: 80 81 $ plessc -r "my less code here" 82 83Finally, by using the -w flag you can watch a specified input file and have it 84compile as needed to the output file: 85 86 $ plessc -w input-file output-file 87 88Errors from watch mode are written to standard out. 89 90The -f flag sets the [output formatter][1]. For example, to compress the 91output run this: 92 93 $ plessc -f=compressed myfile.less 94 95For more help, run `plessc --help` 96 97