News:

Please note these forums are mostly a testing ground for my SMF work and I don't really use them otherwise.

Main Menu

Paste-1207252428:v:use_geshi-1:v:type-php

Started by JayBachatero, Apr 03, 2008, 07:53 PM

Previous topic - Next topic

0 Members and 3 Guests are viewing this topic.

JayBachatero

<?php

$filename = substr($_SERVER['argv'][1], 11);
$lines = file($filename);

$found_reference = false;
$in_list = false;

$references = array();
foreach ($lines as $key => $line)
{
   // We don't like blank lines.
   if (trim($line) == '')
      continue;

   if (trim($line) == '<h3>References</h3>')
      $found_reference = true;

   // First lets check if we even doing references yet then check for list.
   if ($found_reference && trim($line) == '<ol>')
      $in_list = true;

   if (!$found_reference && !$in_list)
      continue;

   // Ok we done here.
   if ($in_list && trim($line) == '</ol>')
   {
      $found_reference = false;
      $in_list = false;
      break;
   }

   // Ok we have a list item.
   if ($in_list && substr(trim($line), 0, 4) == '<li>')
      $references[] = htmlspecialchars(substr(trim($line), 4, -5));
}

//print_r($references);

// Lets make the right XML style now.
$xml =
'      <ref-list>
         <title>References</title>
         <list list-type="order">';
foreach ($references as $reference)
   $xml .= '
            <list-item><p>' . $reference . '</p></list-item>';
$xml .= '
         </list>
      </ref-list>';

echo $xml;

$fp = fopen(dirname($filename) . '/references.xml', 'w+');
if (fwrite($fp, $xml))
   echo "\nWROTE AND SAVED FILE";
fclose($fp);

?>