php template parser

Gestart doorDaiman4 reacties34 weergaven

5 berichten · pagina 1 van 1

Daiman

Lid · Topicstarter

Berichten
5.795
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Hoi,

Ik heb zojuist een simpele template parser gemaakt.
Hij is gratis te gebruiken maar mag niet verveelvoudigd of verkocht worden!

parser.class.php

[COLOR= #0000BB]<?php[/COLOR]
[COLOR= #FF8000]/*
Template parser.
Gemaakt door: Daiman Meijers.
Dit script maakt het mogelijk om php en html gescheiden te houden.
Dit script is gratis te gebruiken.
Het mag niet zonder rechten worden verveelvoudigd of verkocht!
[parser.class.php]
*/[/COLOR]
    [URL="http://www.php.net/class"]class[/URL] parser [COLOR= #007700]{[/COLOR]
        [URL="http://www.php.net/public"]public[/URL] [COLOR= #0000BB]$data[/COLOR][COLOR= #007700];[/COLOR]
        [URL="http://www.php.net/public"]public[/URL] [COLOR= #0000BB]$source[/COLOR][COLOR= #007700];[/COLOR]
        [URL="http://www.php.net/public"]public[/URL] [COLOR= #0000BB]$replace[/COLOR][COLOR= #007700];[/COLOR]
        [URL="http://www.php.net/public"]public[/URL] [COLOR= #0000BB]$naar[/COLOR][COLOR= #007700];[/COLOR]
        [URL="http://www.php.net/public"]public[/URL] [COLOR= #0000BB]$mes[/COLOR][COLOR= #007700];[/COLOR]
        [URL="http://www.php.net/public"]public[/URL] [COLOR= #0000BB]$loc[/COLOR][COLOR= #007700];
        function[/COLOR] getsource[COLOR= #007700]([/COLOR][COLOR= #0000BB]$location[/COLOR][COLOR= #007700]) {[/COLOR]
            [COLOR= #0000BB]$this[/COLOR][COLOR= #007700]->[/COLOR]data [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/file_get_contents"]file_get_contents[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$location[/COLOR][COLOR= #007700]);[/COLOR]
            [COLOR= #0000BB]$this[/COLOR][COLOR= #007700]->[/COLOR]loc [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$location[/COLOR][COLOR= #007700];
        }

        
        function[/COLOR] changesource[COLOR= #007700]([/COLOR][COLOR= #0000BB]$from[/COLOR][COLOR= #007700],[/COLOR][COLOR= #0000BB]$to[/COLOR][COLOR= #007700]) {[/COLOR]
            
            [URL="http://www.php.net/if"]if[/URL] [COLOR= #007700](![/COLOR][URL="http://www.php.net/eregi"]eregi[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$from[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$this[/COLOR][COLOR= #007700]->[/COLOR]data[COLOR= #007700])) {[/COLOR]
                [COLOR= #0000BB]$this[/COLOR][COLOR= #007700]->[/COLOR]mes [COLOR= #007700].=[/COLOR] [COLOR= #DD0000]"<div style=background-color:red;>Kon $from niet vinden in $this->loc</div>"[/COLOR][COLOR= #007700];
            }[/COLOR]

            [COLOR= #0000BB]$this[/COLOR][COLOR= #007700]->[/COLOR]replace[COLOR= #007700][] .=[/COLOR] [COLOR= #0000BB]$from[/COLOR][COLOR= #007700];[/COLOR]
            [COLOR= #0000BB]$this[/COLOR][COLOR= #007700]->[/COLOR]naar[COLOR= #007700][] .=[/COLOR] [COLOR= #0000BB]$to[/COLOR][COLOR= #007700];
        }

        
        function[/COLOR] show[COLOR= #007700]([/COLOR][COLOR= #0000BB]$error_rep[/COLOR][COLOR= #007700]) {[/COLOR]
            [COLOR= #0000BB]$s[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/str_replace"]str_replace[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$this[/COLOR][COLOR= #007700]->[/COLOR]replace[COLOR= #007700],[/COLOR] [COLOR= #0000BB]$this[/COLOR][COLOR= #007700]->[/COLOR]naar[COLOR= #007700],[/COLOR] [COLOR= #0000BB]$this[/COLOR][COLOR= #007700]->[/COLOR]data[COLOR= #007700]);[/COLOR]
            
            [URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$error_rep[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #0000BB]1[/COLOR][COLOR= #007700]) {[/COLOR]
                [COLOR= #0000BB]$s[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$this[/COLOR][COLOR= #007700]->[/COLOR]mes[COLOR= #007700].[/COLOR][COLOR= #0000BB]$s[/COLOR][COLOR= #007700];
            }[/COLOR]

            [URL="http://www.php.net/return"]return[/URL] [COLOR= #0000BB]$s[/COLOR][COLOR= #007700];
        }

    }[/COLOR]

    ?>


Hoe te gebruiken:

[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/include"]include[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"parser.class.php"[/COLOR][COLOR= #007700]);[/COLOR]
[COLOR= #0000BB]$new[/COLOR] [COLOR= #007700]= new[/COLOR] parser[COLOR= #007700];[/COLOR]
[COLOR= #0000BB]$new[/COLOR][COLOR= #007700]->[/COLOR]getsource[COLOR= #007700]([/COLOR][COLOR= #DD0000]"template.html"[/COLOR][COLOR= #007700]);[/COLOR]
[COLOR= #0000BB]$new[/COLOR][COLOR= #007700]->[/COLOR]changesource[COLOR= #007700]([/COLOR][COLOR= #DD0000]%titel%[/COLOR][COLOR= #007700],[/COLOR][COLOR= #DD0000]"daimans parser"[/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #FF8000]// %veld%, waarin het veranderd moet[/COLOR]
[COLOR= #0000BB]$new[/COLOR][COLOR= #007700]->[/COLOR]changesource[COLOR= #007700]([/COLOR][COLOR= #DD0000]%body%[/COLOR][COLOR= #007700],[/COLOR][COLOR= #DD0000]"Content"[/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #FF8000]// %veld%, waarin het veranderd moet  worden[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$new[/COLOR][COLOR= #007700]->[/COLOR]show[COLOR= #007700]([/COLOR][COLOR= #0000BB]0[/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #FF8000]// indien de 0 wordt veranderdt word in 1 dan worden er errors weergegeven[/COLOR]
?>


<html>
<head>
<title>%titel%</title>
</head>
<body>
%body%
</body>
</html>


Tips en/of ideeën zijn altijd welkom
0
Berichten
20.364
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Nice, ik zocht een template parser. Wanneer mijn layout af is ga ik hem uitproberen. biggrin
0
Daiman

Lid · Topicstarter

Berichten
5.795
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Shahiem schreef:
Nice, ik zocht een template parser. Wanneer mijn layout af is ga ik hem uitproberen. biggrin
okay smile
ik ga zo verder met een update er voor zodat hij wat beter wordt
0
Berichten
3.314
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Nice maar jammer dat je je variabelen gewoon als string echot
0
Berichten
20.364
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
En als je dan de paginas in body wil weergeven moet je dan speciaal een pagina systeem hebben want dat gaat lastig met includen.
0

Jouw reactie

Deel je idee, stel een vraag of help een ander verder.

Editor laden…

Praat mee met de One2xs-community.

Inloggen om te reageren