• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Parse custom html tags into CI functions with variables.

#11
[eluser]duffy0[/eluser]
I have this code working! How can I use hooks to parse the output? Examples please? Undecided

Code:
<?php

Class Ilml {

    function searchTags($output) {
        $reg = "#<il:(.*?)\s+(.*?)\s*(>(.*?)</il:\\1>|/>)#mis";

        if (preg_match($reg, $output)) {
            
            $output = preg_replace_callback($reg,array($this,"tagparser"),$output,-1);
            return $this->searchtags($output);
        } else {
            return $output;
        }
    }


    function tagparser($array) {
        $query = $array[0];
        $tagName =  $array[1];
        $tagArgs =  $array[2];
        $tagContent =  $array[4];
        $argsArray = array();
        
        $tagName = str_replace("-","_", $tagName);
        
        $tagArgs = str_replace("\\\"","[[QUOTE]]",$tagArgs);
        preg_match_all("#([a-z1-9]+)\s*=(([a-z0-9_-]+)|[\"?](.[^\"]+)[\"?])#mis",$tagArgs,$args);
        foreach ($args[1] as $id=>$var) {
            $argsArray[$var] = $this->correctValue($args[2][$id]);
        }        
        
        // parse nested tags
        $tagContent = $this->searchtags($tagContent);
        
        /* Load the ILML helper. */
        
        /* Do the template function. */
        if (function_exists("ilml_$tagName")) {
            $function = "ilml_$tagName";
            return $function($tagContent, $argsArray);
        } else {
            return $tagContent;
        }
    }
}

function ilml_boxtitle($content, $args=null) {
    return "<h4 style=\"border-bottom: thin solid; margin-bottom: 5px;\">".$content."</h4>";
}

$ilml = new Ilml();
print '&lt;html&gt;
&lt;head&gt;&lt;title>test&lt;/title&gt;&lt;/head>
&lt;body&gt;';


echo $ilml->searchTags('<il:boxtitle >Followers</il:boxtitle>');

print'
&lt;/body&gt;
&lt;/html&gt;';

?&gt;

#12
[eluser]pistolPete[/eluser]
There's no need to use a hook.
Use the _output() function of the controller class:
Processing Output

#13
[eluser]duffy0[/eluser]
How would I do this? I have created a library file for the Ilml Class. Would I make it a controller instead and how would I implement _output()???

I have also made it so all the tags processing functions are in a helper file.

#14
[eluser]duffy0[/eluser]
I figured it out.. thanks for all the help! I will be posting my code in the Ignited Code forum soon.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.