\n"; echo "Example: php dokuwiki2mediawiki start.txt\n"; } else for ($argument=1;$argument<$argc;$argument++) { $filename=$argv[$argument]; $inputfile=fopen($filename,"r"); $i=0; $output=""; if ($inputfile) { while (!feof($inputfile)) { $lines[$i++]=fgets($inputfile); //we start counting a 0 } fclose($inputfile); } $linecount=$i; $i=-1; while (++$i<$linecount) { if ($in_table) $row++; // replace headings $line=$lines[$i]; if (preg_match('/^ *======.*====== *$/',$line)) { $line=preg_replace('/^ *======/','=',$line); $line=preg_replace('/====== *$/','=',$line); } elseif (preg_match('/^ *=====.*===== *$/',$line)) { $line=preg_replace('/^ *=====/','==',$line); $line=preg_replace('/===== *$/','==',$line); } elseif (preg_match('/^ *====.*==== *$/',$line)) { $line=preg_replace('/^ *====/','===',$line); $line=preg_replace('/==== *$/','===',$line); } elseif (preg_match('/^ *===.*=== *$/',$line)) { $line=preg_replace('/^ *===/','====',$line); $line=preg_replace('/=== *$/','====',$line); } elseif (preg_match('/^ *==.*== *$/',$line)) { $line=preg_replace('/^ *==/','=====',$line); $line=preg_replace('/== *$/','=====',$line); } // end of replace headings // replace bulletpoints $level=0; // level of bulletpoints, e.g. * is level 1, *** is level 3. while (preg_match('/^( )+\*/',$line)) { $line=preg_replace("/^ /","",$line); $level++; } while ($level>1) { $line="*".$line; $level--; } // end of replace bulletpoints // replace ordered list items $level=0; // level of list items, e.g. - is level 1, --- is level 3. while (preg_match('/^( )+\-/',$line)) { $line=preg_replace("/^ /","",$line); $level++; $line=preg_replace("/^-/","#",$line); } while ($level>1) { $line="#".$line; $level--; } // end of replace ordered list items // replace // $line=preg_replace("/\/\//","''",$line); // end of replace // // replace ** $line=preg_replace("/\*\*/","'''",$line); // end of replace ** // replace \\ // thanks to Rakete Kalle $line=preg_replace("/\\\\\\\\ /","
",$line); // end of replace \\ // begin care for tables if (preg_match("/^\|/",$line)) { $line=preg_replace("/\| *$/","",$line); $line=preg_replace("/\n/","",$line); if (!$in_table) { $in_table=true; $row=1; } $cells[$row]=explode("|",preg_replace("/^\|/","",$line)); } // have we left a table? if ((!preg_match("/^\|/",$line)) && $in_table) { $in_table=false; if ($headers!="") for ($n=0;$n=1) { if ($rowspancells[$y][$x]>1) $tablesource.="rowspan=".$rowspancells[$y][$x]."|"; $tablesource.=$cells[$y][$x]; if ($x