/*
-----------------------------------------------------------------------------
Program: HTML2WIKI.php
Version: 1.4 (18 april 2006)
-----------------------------------------------------------------------------
Coder: Kuronokoneko
Home: http://www.solosequenosenada.com/misc/html2wiki/html2wiki.php
Place: Brisbane (Australia)
License: Freeware
-----------------------------------------------------------------------------
Description: This HTML parser in PHP is for convert HTML code to Wiki code.
You can copy, use and modify this PHP code in the way that you like.
-----------------------------------------------------------------------------
Descripcion: Este parseador de HTML realizado en PHP sirve para convertir
codigo HTML en codigo Wiki. Espero que lo disfrutes.
Puedes copiar, usar y modificar este codigo PHP de la manera que quieras.
-----------------------------------------------------------------------------
*/
$html_source="";
// Get params
// Recoge parámetros
if (!empty($_POST['htmlSource'])) {
$html_source=$_POST['htmlSource'];
} else {
$html_source="<B>Put here your HTML code</B>\n<BR><I>Escribe aquí tu código HTML</I>";
}
?>
<FORM
METHOD="post" ACTION="html2wiki.php">
<B>HTML code:</B><BR>
<textarea rows="16" name="htmlSource"
cols="60"><? print $html_source; ?></textarea>
<BR><input type="submit"
value="Translate HTML to WIKI" name="enviar">
<?php
$html_source=LinealizerOutput($html_source);
function LinealizerOutput($output)
{
$output = preg_replace('/\t{1,}/', ' ', $output);
$output = preg_replace('/\n{1,}/', ' ', $output);
$output = preg_replace('/\r{1,}/', ' ', $output);
$output = preg_replace('/\s{1,}/', ' ', $output);
$output = str_replace('> <', '><', $output);
$output = str_replace(' >', '>', $output);
$output = str_replace('\"', '"', $output);
$output = str_replace('\'', '"', $output);
return $output;
}// Convert all HTML labels to upper case.
// Pasa todas las etiquetas HTML a mayuscula.$html_source=preg_replace("/(<\/?)(\w+)([^>]*>)/e", "'\\1'.strtoupper('\\2').'\\3'", $html_source);
// ----------------
// PATTERNS BOCK 0
// ----------------$html_source=str_replace('<BR>', "\n", $html_source);
$html_source=str_replace('<BR />', "\n", $html_source);
$html_source=str_replace('<PRE>', '', $html_source);
$html_source=str_replace('</PRE>', '', $html_source);
$html_source=str_replace('</B>', '\'\'\'', $html_source);
$html_source=str_replace('<EM>', '\'\'\'', $html_source);
$html_source=str_replace('</EM>', '\'\'\'', $html_source);
$html_source=str_replace('<STRONG>', '\'\'\'', $html_source);
$html_source=str_replace('</STRONG>', '\'\'\'', $html_source);
$html_source=str_replace('<CENTER>', '', $html_source);
$html_source=str_replace('</CENTER>', '', $html_source);
$html_source=str_replace('<UL>', '', $html_source);
$html_source=str_replace('</UL>', '', $html_source);
$html_source=str_replace('<U>', '', $html_source);
$html_source=str_replace('</U>', '', $html_source);
$html_source=str_replace('<OL>', '', $html_source);
$html_source=str_replace('</OL>', '', $html_source);
$html_source=str_replace('</LI>', '', $html_source);
$html_source=str_replace('</TH>', '! heading', $html_source);
$html_source=str_replace('</TR>', '', $html_source);
$html_source=str_replace('</TD>', '', $html_source);
$html_source=str_replace('</DIV>', '', $html_source);
$html_source=str_replace('</P>', '', $html_source);
$html_source=str_replace('</CAPTION>', '', $html_source);
$html_source=str_replace('</A>', ']', $html_source);
$html_source=str_replace('</I>','\'\'', $html_source);
$html_source=str_replace('<BLOCKQUOTE>', '\'\'', $html_source);
$html_source=str_replace('</BLOCKQUOTE>', '\'\'', $html_source);
$html_source=str_replace('<CITE>', '\'\'', $html_source);
$html_source=str_replace('</CITE>', '\'\'', $html_source);
$html_source=str_replace('<SMALL>', '', $html_source);
$html_source=str_replace('</SMALL>', '', $html_source);
$html_source=str_replace('</HTML>', '', $html_source);
$html_source=str_replace('<TBODY>', '', $html_source);
$html_source=str_replace('</TBODY>', '', $html_source);
$html_source=str_replace('</FONT>', '', $html_source);
$html_source=str_replace('</TITLE>', '', $html_source);
$html_source=str_replace('</HEAD>', '', $html_source);
$html_source=str_replace('</SPAN>', '', $html_source);
$html_source=str_replace('</BODY>', '', $html_source);
$html_source=str_replace('</H1>', "=\n", $html_source);
$html_source=str_replace('</H2>', "==\n", $html_source);
$html_source=str_replace('</H3>', "===\n", $html_source);
$html_source=str_replace('</H4>', "====\n", $html_source);
$html_source=str_replace('</H5>', "=====\n", $html_source);
$html_source=str_replace('</FORM>', '', $html_source);
$html_source=str_replace('</LINK>', '', $html_source);
$html_source=str_replace("\n ", "\n", $html_source);
// Is necessary to improve the labels <IMG>, <A>, <SCRIPT> and <TH>
// Faltan mejorar las etiquetas <IMG>, <A>, <SCRIPT> y <TH> (TH=encabezados de columnas de tabla)// ----------------
// PATTERNS BOCK 1
// ----------------$patterns1 = array(
"/\<TABLE(.*?)\>/",
"/\<\/TABLE\>/",
"/\<TR(.*?)\>/",
"/\<TD(.*?)\>/",
"/\<DIV(.*?)\>/",
"/\<P(.*?)\>/",
"/\<CAPTION(.*?)\>/",
"/\<IMG SRC=\"\;(.*?)\"\;\>/",
"/\<IMG SRC=(.*?)\>/",
"/\<IMG src=\"\;(.*?)\"\;\>/",
"/\<IMG src=(.*?)\>/",
"/\<IMG (.*?)\>/"
);$replacements1 = array(
"\n{| \\1",
"\n|}",
"\n|- \\1",
"\n| ",
"",
"\n\n",
"\n|+ \\1",
"\n[[Imagen:\\1]]",
"\n[[Imagen:\\1]]",
"\n[[Imagen:\\1]]",
"\n[[Imagen:\\1]]",
"\n[[Imagen:\\1]]"
);$html_source = preg_replace($patterns1,$replacements1, $html_source);
// ----------------
// PATTERNS BOCK 2
// ----------------$patterns2 = array(
"/\<A href=\"\;(.*?)\"\;\>/",
"/\<A href=\"\;(.*?)\"\;\>/",
"/\<A HREF=(.*?)\>/",
"/\<A href=(.*?)\>/",
"/\<A NAME=(.*?)\>/",
"/\<A (.*?)\>/",
"/\<HR(.*?)\>/",
"/\<TH(.*?)\>/",
"/\<HEAD(.*?)\>/",
"/\<SCRIPT(.*?)\>(.*?)<\/SCRIPT\>/",
"/\<HTML(.*?)\>/",
"/\<FONT(.*?)\>/",
"/\<TITLE(.*?)\>/",
"/\<META(.*?)\>/",
"/\<BODY (.*?)\>/",
"/\<H1(.*?)\>/",
"/\<H2(.*?)\>/",
"/\<H3(.*?)\>/",
"/\<H4(.*?)\>/",
"/\<H5(.*?)\>/",
"/\<!DOCTYPE (.*?)\>/",
"/\<!(.*?)\>/"
);
$replacements2 = array(
"\n[\\1 ",
"\n[\\1 ",
"\n[\\1 ",
"\n[\\1 ",
"",
"\n[\\1 ",
"\n----",
"\n\! ",
"",
"",
"",
"",
"",
"",
"\n",
"\n\n=",
"\n\n==",
"\n\n===",
"\n\n====",
"\n\n=====",
"",
""
);$html_source = preg_replace($patterns2,$replacements2, $html_source);
// ----------------
// PATTERNS BOCK 3
// ----------------$patterns3 = array(
"/\<O:(.*?)\>/",
"/\<\/O:(.*?)\>/",
"/\<V:(.*?)\>/",
"/\<\/V:(.*?)\>/",
"/\<B(.*?)\>/",
"/\<I(.*?)\>/",
"/\<SPAN(.*?)\>/",
"/\<LINK(.*?)\>/",
"/\<FORM(.*?)\>/",
"/\<INPUT(.*?)\>/",
"/\<LI(.*?)\>/"
);
$replacements3 = array(
"\n",
"\n",
"",
"",
"'''",
"''",
"",
"",
"",
"",
"\n* "
);$html_source = preg_replace($patterns3,$replacements3, $html_source);
$html_source=str_replace(' ', ' ', $html_source);
$html_source=str_replace(chr(10).chr(10).chr(10), chr(10), $html_source);
$html_source=str_replace(chr(13).chr(13).chr(13), chr(13), $html_source);
$html_source=str_replace('\n\n\n', '\n', $html_source);
$html_source=str_replace('\r\r\r', '\r', $html_source);
$html_source=str_replace('%0D%0A%0D', '%0A', $html_source);
?>
<B>Translated Wiki code:</B><BR>
<textarea rows="16" name="wikiSource"
cols="60"><? print $html_source;
?></textarea>
</FORM>
<BR><BR>
<FONT SIZE=1>
ENGLISH: This page is for convert HTML code to Wiki code. <BR>HTML2Wiki
has programed in PHP, you can download the <A HREF="http://www.solosequenosenada.com/misc/html2wiki/html2wiki.php"
alt="_blank">source code of html2wiki.php</A>
<BR><BR>
SPANISH: Esta página es para pasar código HTML a código
Wiki. <BR>HTML2Wiki ha sido programado en PHP, si quieres puedes bajarte
el <A HREF="http://www.solosequenosenada.com/misc/html2wiki/html2wiki.php"
alt="_blank">código fuente de html2wiki.php</A><BR>
<BR><BR>
You can download the last copy of <A HREF="http://www.solosequenosenada.com/misc/html2wiki/html2wiki.php">html2wiki</A>
in <A HREF="http://www.solosequenosenada.com">solosequenosenada.com</A>.
</FONT>
</FONT>
</CENTER>
</BODY>
</HTML>