Location: PHPKode > scripts > XCS Parser > xcs-parser/examples/syntax.php
<?php
/**
 * Advanced syntax changing test/demo file for XcsParser class.
 */

error_reporting(E_ALL | E_STRICT);
include '../lib/XcsParser_class.php';

/**
 * XcsParser dollar syntax class.
 * Note 2 hash characters (##) as the new line comment start mark.
 * This is because a single hash appears natively in CSS, as a
 * color code beginning character (e.g. #FF33AA).
 */
final class DollarXcsParser extends XcsParser {

	/**
	 * New XCS variable name prefix.
	 */
	protected $varNamePrefix = '$';

	/**
	 * New XCS variable name regex.
	 */
	protected $varNameRx = '\$[A-Za-z0-9_-]+';

	/**
	 * New XCS line comment start regex.
	 */
	protected $lineCommentStartRx = '##';
}

/**
 * XcsParser percent syntax class.
 */
final class PercentXcsParser extends XcsParser {

	/**
	 * New XCS variable name prefix.
	 */
	protected $varNamePrefix = '%';

	/**
	 * New XCS variable name regex.
	 */
	protected $varNameRx = '%[A-Za-z0-9_-]+';

	/**
	 * New XCS line comment start regex.
	 */
	protected $lineCommentStartRx = '\^';
}

$css1 = file_get_contents('../etc/advanced_syntax_1.css');
$css2 = file_get_contents('../etc/advanced_syntax_2.css');
$sp1 = new DollarXcsParser($css1);
$sp2 = new PercentXcsParser($css2);

echo $sp1->parse()->getCss();
echo $sp2->parse()->getCss();

if ($sp1->getCss() != $sp2->getCss()) {
	echo "\n<h1>Error</h1>\n";
} else echo "\n<h1>All good!</h1>\n";
?>
Return current item: XCS Parser