Login   Register  
PHP Classes
elePHPant
Icontem

File: test_css_parser.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Manuel Lemos  >  Secure HTML parser and filter  >  test_css_parser.php  >  Download  
File: test_css_parser.php
Role: Example script
Content type: text/plain
Description: CSS parser test script
Class: Secure HTML parser and filter
Parse and filter insecure HTML tags and CSS styles
Author: By
Last change: Made the parser track error lines.
Date: 4 years ago
Size: 1,185 bytes
 

Contents

Class file image Download
<?php
/*
 * test_css_parser.php
 *
 * @(#) $Header: /home/mlemos/cvsroot/markupparser/test_css_parser.php,v 1.4 2009/10/31 20:24:15 mlemos Exp $
 *
 */

    
require_once('css_parser.php');

    
$stylesheet = ((IsSet($_SERVER['argv']) && count($_SERVER['argv'])>1) ? $_SERVER['argv'][1] : '');

    
$css = new css_parser_class;
    
$css->track_lines 1;

/*
 * The following lines are for testing purposes.
 * Remove these lines when adapting this example to real applications.
 */
    
if(defined('__TEST'))
    {
        if(IsSet(
$__test_options['Stylesheet']))
            
$stylesheet $__test_options['Stylesheet'];
    }

    if(
$css->ParseStylesheet($stylesheet$styles))
    {
        
$ts count($styles);
        for(
$s 0$s $ts; ++$s)
            
var_dump($styles[$s]);
    }
    else
    {
        echo 
'CSS parsing error: '.$css->error.' at position '.$css->error_position;
        if(
$css->track_lines
        
&& $css->GetPositionLine($css->error_position$line$column))
            echo 
' line '$line' column '$column;
        echo 
"\n";
    }
    for(
$warning 0Reset($css->warnings); $warning count($css->warnings); Next($css->warnings), $warning++)
    {
        
$w Key($css->warnings);
        echo 
'Warning: '$css->warnings[$w], ' at position '$w;
        echo 
"\n";
    }
?>