Location: PHPKode > projects > PhpWebDesk > phpWebDesk/convert_m.php
<?php
#
# phpWebDesk Markup Converter
# (c) 2003 Andrew Godwin
#
# Turn Short_Tags OFF! Otherwise PHP will play silly buggers with the WML (xml) <? tags.
#

# If the $output2var is enabled then will output to the variable
# $markeroutput, rather than echoing it all. Useful for includes.

# Modes
# Basic functionality for this at the moment. You've got input in TML
# (Transferable Markup Language; like HTML, only different) and output
# in HTML, WML (WAP Markup Language. One of my inspirations for this)
# and plain ASCII text with things like *italic* and !bold!. Don't know about those
# last formatting things, may take 'em off or put them in a seperate mode.
#
# 0 - HTML
# 1 - WML
# 2 - Plain Text

if(!file_exists($if)) { die("Come on, give us a (valid?) filename.");}

// Open input file
$fn = fopen($if, "r");

// Open template files ------------------------------------------

# Input template
$file2scan=file_get_contents($if);
if (stristr($file2scan, "<html>")) { $imode=1;}
if (stristr($file2scan, "<wml>")) { $imode=2;}
if (stristr($file2scan, "<tml>")) { $imode=0;}

switch ($imode) {
    case 0:
        $ininc=("templates/tml.inc");
        break;
    case 1:
        $ininc=("templates/html.inc");
        break;
    case 2:
        $ininc=("templates/wml.inc");
        break;
    case 3:
        $ininc=("templates/ascii.inc");
        break;
}
include $ininc;
$itemplate = $template;

# Output template
switch ($mode) {
    case 0:
        $outinc=("templates/html.inc");
        break;
    case 1:
        $outinc=("templates/wml.inc");
        break;
    case 2:
        $outinc=("templates/ascii.inc");
        break;
    case 2:
        $outinc=("templates/tml.inc");
        break;
}
include $outinc;

while(!feof($fn)){
$body.=fgets($fn)or die("invalid file handle");
}

// Body --------------------------------------------------------

# Do tags, but skip title.
foreach($itemplate as $tempr => $tag) {
    $body = str_replace($tag, $template[$tempr], $body);
}

if(!$output2var) {
echo $body;
}
$markeroutput.=$body;

// Close input file
fclose($fn);

?>
Return current item: PhpWebDesk