itais ics parser framework

This is where you share YOUR scripts with others

Moderators: egami, macek, gesf

Post Reply
Flake
New php-forum User
New php-forum User
Posts: 8
Joined: Sat Mar 18, 2017 8:04 am

Wed Apr 26, 2017 9:28 am

Hi!
Here with a new parsing framework after a rewrite of my previous one due to the fact that I rewrote the whole software because it was incredibly messy and inconsistent.

This time it is complete with inline tags and error reporting.

Here's a simple example:

Code: Select all

<?php
$parser = new \itais\ics\parser\Parser;

$parser->code         = "<red>The time is: </red> <time>";
$parser->callback    function ($tag)
{
    if ($tag->type == \itais\ics\parser\TagType::Start)
    {
        if ($tag->command == "time")
        {
       		$signal = new \itais\ics\parser\Signal;
       		
        	$signal->inline      = true; //this is an inlined tag
        	$signal->output    = time(); //and it represents the time
        	
        	return $signal;
        }
        else
        {
        	$signal = new \itais\ics\parser\Signal;
        	$signal->inline    = false;
        	
        	return $signal;
        }
    }
    else
    {
    	if ($tag->command == "color")
    	{
    	    $signal = new \itais\ics\parser\Signal;
    	    
    	    $signal->output    = "<span style=\"color: red\">{$tag->content}</span>";
    	    
    	    return $signal;
    	}
    }
    
    //if we haven't handled it yet
    $signal = new \itais\ics\parser\Signal;
    	    
    $signal->output    = $tag->content;
    	    
    return $signal;
}

$parser->Parse();

echo $parser->output;
However, this is just the tip of the iceberg. Look through the source to find out more.
Attachments
parser.7z
(3.16 KiB) Downloaded 18 times

Post Reply
  • Information
  • Who is online

    Users browsing this forum: Bing [Bot] and 1 guest