Genealogy_Gedcom
[ class tree: Genealogy_Gedcom ] [ index: Genealogy_Gedcom ] [ all elements ]

Source for file Genealogy_Parser.php

Documentation is available at Genealogy_Parser.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------+
  4. // | PHP Version 4                                                        |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2003 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.02 of the PHP license,      |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available at through the world-wide-web at                           |
  11. // | http://www.php.net/license/2_02.txt.                                 |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Olivier Vanhoucke <olivier@php.net>                         |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id: Genealogy_Parser.php,v 1.2 2003/01/04 11:54:56 mj Exp $
  20. //
  21.  
  22. require_once 'Individual.php';
  23. require_once 'Family.php';
  24. require_once 'Object.php';
  25. require_once 'Header.php';
  26.  
  27. /**
  28.  * Genealogy_Parser
  29.  *
  30.  * Purpose:
  31.  *
  32.  *     Gedcom file parser
  33.  *
  34.  * Contributors:
  35.  *
  36.  * @author   Olivier Vanhoucke <olivier@php.net>
  37.  * @version  $Revision: 1.2 $
  38.  * @package  Genealogy_Gedcom
  39.  * @access   private
  40.  */
  41. class Genealogy_Parser {
  42.  
  43.     /**
  44.      * Contains Gedcom filename
  45.      *
  46.      * @var    string 
  47.      * @access private
  48.      */
  49.     var $_GedcomFile                  '';
  50.  
  51.     /**
  52.      * Contains all lines of the Gedcom file
  53.      *
  54.      * @var    array 
  55.      * @access private
  56.      */
  57.     var $_FileContent                 = array();
  58.  
  59.     /**
  60.      * Contains the all tree of the file contain
  61.      *
  62.      * @var    array 
  63.      * @access private
  64.      */
  65.     var $_GedcomTree                  = array();
  66.  
  67.     /**
  68.      * Contains the header tree
  69.      *
  70.      * @var    array 
  71.      * @access private
  72.      */
  73.     var $_GedcomHeaderTree            = array();
  74.  
  75.     /**
  76.      * Contains the individuals tree
  77.      *
  78.      * @var    array 
  79.      * @access private
  80.      */
  81.     var $_GedcomIndividualsTree       = array();
  82.  
  83.     /**
  84.      * Contains the families tree
  85.      *
  86.      * @var    array 
  87.      * @access private
  88.      */
  89.     var $_GedcomFamiliesTree          = array();
  90.  
  91.     /**
  92.      * Contains the objects tree
  93.      *
  94.      * @var    array 
  95.      * @access private
  96.      */
  97.     var $_GedcomObjectsTree           = array();
  98.  
  99.     /**
  100.      * Contains an array of Genealogy_Individual object
  101.      *
  102.      * @var    array 
  103.      * @access public
  104.      */
  105.     var $GedcomIndividualsTreeObjects = array();
  106.  
  107.     /**
  108.      * Contains an array of Genealogy_Family object
  109.      *
  110.      * @var    array 
  111.      * @access public
  112.      */
  113.     var $GedcomFamiliesTreeObjects    = array();
  114.  
  115.     /**
  116.      * Contains an array of Genealogy_Object object
  117.      *
  118.      * @var    array 
  119.      * @access public
  120.      */
  121.     var $GedcomObjectsTreeObjects     = array();
  122.  
  123.     /**
  124.      * Contains a Genealogy_Header object
  125.      *
  126.      * @var    array 
  127.      * @access public
  128.      */
  129.     var $GedcomHeaderTreeObject       = array();
  130.  
  131.     /**
  132.      * Display error
  133.      *
  134.      * @param  string message
  135.      * @return string error message
  136.      * @access private
  137.      */
  138.     function _raiseError($msg{
  139.         include_once 'PEAR.php';
  140.         PEAR::raiseError('<b>Genealogy_Parser Error : </b>'.$msgnullPEAR_ERROR_DIE);
  141.     }
  142.  
  143.     /**
  144.      * Launch parsing (use in Genealogy_Gedcom constructor)
  145.      *
  146.      * @access private
  147.      */
  148.     function parse({
  149.         $this->_getFileContent();
  150.  
  151.         if ($this->_isValidGedcomFile()) {
  152.           $this->_makeGedcomTree();
  153.           $this->_parseTree();
  154.           $this->_parseHeader();
  155.           $this->_parseIndividuals();
  156.           $this->_parseFamilies();
  157.           $this->_parseObjects();
  158.  
  159.           unset($this->_FileContent);
  160.           unset($this->_GedcomTree);
  161.           unset($this->_GedcomHeaderTree);
  162.         else {
  163.           Genealogy_Parser::_raiseError($this->_GedcomFile.' is not a valid Gedcom file.');
  164.         }
  165.     }
  166.  
  167.     /**
  168.      * Read Gedcom file contains
  169.      *
  170.      * @access private
  171.      */
  172.     function _getFileContent({
  173.         $buffer = array();
  174.         if ($fp @fopen($this->_GedcomFile'r')) {
  175.           while (!feof($fp)) {
  176.                 $buffer[trim(fgets($fp1024));
  177.           }
  178.           fclose($fp);
  179.           // unset the last line if it's empty
  180.           if (empty($buffer[count($buffer- 1])) {
  181.              unset($buffer[count($buffer- 1]);
  182.           }
  183.           $this->_FileContent $buffer;
  184.           unset($buffer);
  185.         else {
  186.           Genealogy_Parser::_raiseError('Cannot open file '.$this->_GedcomFile);
  187.         }
  188.     }
  189.  
  190.     /**
  191.      * Test if it's a valid gedcom file
  192.      *
  193.      * @access private
  194.      * @return boolean 
  195.      */
  196.      function _isValidGedcomFile({
  197.         return (($this->_FileContent[0== '0 HEAD'&& ($this->_FileContent[count($this->_FileContent- 1== '0 TRLR')) ? true : false;
  198.      }
  199.  
  200.     /**
  201.      * Build Gedcom tree
  202.      *
  203.      * $gedcom = array('0 xxx', '1 yyy', '2 zzz', '0 xxx', '1 yyy');
  204.      * $tree   = array(array('0 xxx', '1 yyy', '2 zzz'),
  205.      *                 array('0 xxx', '1 yyy')
  206.      *                );
  207.      *
  208.      * @access private
  209.      */
  210.     function _makeGedcomTree({
  211.         $i = -1;
  212.         foreach ($this->_FileContent as $element{
  213.                 if (!empty($element)) {
  214.                    if ($element{0== '0'{
  215.                       $i++;
  216.                       $this->_GedcomTree[$i= array();
  217.                    }
  218.                    $this->_GedcomTree[$i][$element;
  219.                 }
  220.         }
  221.     }
  222.  
  223.     /**
  224.      * Parse Gedcom tree
  225.      *
  226.      * Separate Gedcom tree in 4 parts : gedcom file header, individuals, families, objects.
  227.      *
  228.      * @access private
  229.      */
  230.      function _parseTree({
  231.         /* could replace \d* -> 0 */
  232.         foreach ($this->_GedcomTree as $element{
  233.             if (@preg_match('/0 @I\d*@ INDI/US'$element[0])) {
  234.               $this->_GedcomIndividualsTree[$element;
  235.             }
  236.             if (@preg_match('/0 @F\d*@ FAM/US',  $element[0])) {
  237.               $this->_GedcomFamiliesTree[$element;
  238.             }
  239.             if (@preg_match('/0 @O\d*@ OBJE/US'$element[0])) {
  240.               $this->_GedcomObjectsTree[$element;
  241.             }
  242.         }
  243.     }
  244.  
  245.     /**
  246.      * Parse Gedcom file header
  247.      *
  248.      * Create a Genealogy_Header object
  249.      *
  250.      * @access private
  251.      */
  252.      function _parseHeader({
  253.         $this->_GedcomHeaderTree $this->_GedcomTree[0];
  254.  
  255.         $Genealogy_Header_Param = array(@preg_replace('/\d VERS (.*)/US',     '$1'$this->_GedcomHeaderTree[$this->_subTag($this->_GedcomHeaderTree'GEDC''VERS')]),
  256.                                         @preg_replace('/\d FORM (.*)/US',     '$1'$this->_GedcomHeaderTree[$this->_subTag($this->_GedcomHeaderTree'GEDC''FORM')]),
  257.                                         @preg_replace('/\d DATE (.*)/US',     '$1'$this->_GedcomHeaderTree[$this->_tag($this->_GedcomHeaderTree'DATE')]),
  258.                                         @preg_replace('/\d TIME (.*)/US',     '$1'$this->_GedcomHeaderTree[$this->_subTag($this->_GedcomHeaderTree'DATE''TIME')]),
  259.                                         @preg_replace('/\d NAME (.*)/US',     '$1'$this->_GedcomHeaderTree[$this->_subTag($this->_GedcomHeaderTree'SOUR''NAME')]),
  260.                                         @preg_replace('/\d VERS (.*)/US',     '$1'$this->_GedcomHeaderTree[$this->_subTag($this->_GedcomHeaderTree'SOUR''VERS')]),
  261.                                         @preg_replace('/\d CORP (.*)/US',     '$1'$this->_GedcomHeaderTree[$this->_subTag($this->_GedcomHeaderTree'SOUR''CORP')]),
  262.                                         @preg_replace('/\d ADDR (.*)/US',     '$1'$this->_GedcomHeaderTree[$this->_subTag($this->_GedcomHeaderTree'SOUR''ADDR')]),
  263.                                         @preg_replace('/\d ADR1 (.*)/US',     '$1'$this->_GedcomHeaderTree[$this->_subTag($this->_GedcomHeaderTree'SOUR''ADR1')]),
  264.                                         @preg_replace('/\d ADR2 (.*)/US',     '$1'$this->_GedcomHeaderTree[$this->_subTag($this->_GedcomHeaderTree'SOUR''ADR2')]),
  265.                                         @preg_replace('/\d CITY (.*)/US',     '$1'$this->_GedcomHeaderTree[$this->_subTag($this->_GedcomHeaderTree'SOUR''CITY')]),
  266.                                         @preg_replace('/\d POST (.*)/US',     '$1'$this->_GedcomHeaderTree[$this->_subTag($this->_GedcomHeaderTree'SOUR''POST')]),
  267.                                         @preg_replace('/\d CTRY (.*)/US',     '$1'$this->_GedcomHeaderTree[$this->_subTag($this->_GedcomHeaderTree'SOUR''CTRY')]),
  268.                                         @preg_replace('/\d PHON (.*)/US',     '$1'$this->_GedcomHeaderTree[$this->_subTag($this->_GedcomHeaderTree'SOUR''PHON')]),
  269.                                         @preg_replace('/\d DATA (.*)/US',     '$1'$this->_GedcomHeaderTree[$this->_subTag($this->_GedcomHeaderTree'SOUR''DATA')]),
  270.                                         @preg_replace('/\d OBJE @(O\d*)@/US''$1'$this->_GedcomHeaderTree[$this->_tag($this->_GedcomHeaderTree'OBJE')]),
  271.                                         @preg_replace('/\d LANG (.*)/US',     '$1'$this->_GedcomHeaderTree[$this->_tag($this->_GedcomHeaderTree'LANG')]),
  272.                                         @preg_replace('/\d CHAR (.*)/US',     '$1'$this->_GedcomHeaderTree[$this->_tag($this->_GedcomHeaderTree'CHAR')]),
  273.                                         @preg_replace('/\d COPR (.*)/US',     '$1'$this->_GedcomHeaderTree[$this->_tag($this->_GedcomHeaderTree'COPR')]),
  274.                                         @preg_replace('/\d FILE (.*)/US',     '$1'$this->_GedcomHeaderTree[$this->_tag($this->_GedcomHeaderTree'FILE')]),
  275.                                         @preg_replace('/\d NAME (.*)/US',     '$1'$this->_GedcomTree[1][$this->_subTag($this->_GedcomTree[1]'SUBM''NAME')]),
  276.                                         @preg_replace('/\d NOTE (.*)/US',     '$1'$this->_GedcomTree[1][$this->_subTag($this->_GedcomTree[1]'SUBM''NOTE')]),
  277.                                         $this->_contTag($this->_GedcomTree[1]'ADDR'),
  278.                                         @preg_replace('/\d PHON (.*)/US',     '$1'$this->_GedcomTree[1][$this->_subTag($this->_GedcomTree[1]'SUBM''PHON')])
  279.                                         );
  280.  
  281.         $this->GedcomHeaderTreeObject =new Genealogy_Header($Genealogy_Header_Param);
  282.  
  283.         unset($Genealogy_Header_Param);
  284.     }
  285.  
  286.     /**
  287.      * Parse individuals tree
  288.      *
  289.      * Create an array of Genealogy_Individual object
  290.      *
  291.      * @access private
  292.      */
  293.     function _parseIndividuals({
  294.         for ($i=0; $i count($this->_GedcomIndividualsTree)$i++{
  295.             $Genealogy_Individual_Param = array(@preg_replace('/0 @(I\d*)@ INDI/US',      '$1'$this->_GedcomIndividualsTree[$i][0]),
  296.                                                 @preg_replace('/\d NAME (.*)\/(.*)\//US''$2'$this->_GedcomIndividualsTree[$i][$this->_tag($this->_GedcomIndividualsTree[$i]'NAME')]),
  297.                                                 @preg_replace('/\d NAME (.*)\/(.*)\//US''$1'$this->_GedcomIndividualsTree[$i][$this->_tag($this->_GedcomIndividualsTree[$i]'NAME')]),
  298.                                                 @preg_replace('/\d NICK (.*)/US',         '$1'$this->_GedcomIndividualsTree[$i][$this->_tag($this->_GedcomIndividualsTree[$i]'NICK')]),
  299.                                                 @preg_replace('/\d TITL (.*)/US',         '$1'$this->_GedcomIndividualsTree[$i][$this->_tag($this->_GedcomIndividualsTree[$i]'TITL')]),
  300.                                                 @preg_replace('/\d DATE (.*)/US',         '$1'$this->_GedcomIndividualsTree[$i][$this->_subTag($this->_GedcomIndividualsTree[$i]'BIRT''DATE')]),
  301.                                                 @preg_replace('/\d PLAC (.*)/US',         '$1'$this->_GedcomIndividualsTree[$i][$this->_subTag($this->_GedcomIndividualsTree[$i]'BIRT''PLAC')]),
  302.                                                 @preg_replace('/\d SOUR (.*)/US',         '$1'$this->_GedcomIndividualsTree[$i][$this->_subTag($this->_GedcomIndividualsTree[$i]'BIRT''SOUR')]),
  303.                                                 @preg_replace('/\d NOTE (.*)/US',         '$1'$this->_GedcomIndividualsTree[$i][$this->_subTag($this->_GedcomIndividualsTree[$i]'BIRT''NOTE')]),
  304.                                                 @preg_replace('/\d DATE (.*)/US',         '$1'$this->_GedcomIndividualsTree[$i][$this->_subTag($this->_GedcomIndividualsTree[$i]'DEAT''DATE')]),
  305.                                                 @preg_replace('/\d PLAC (.*)/US',         '$1'$this->_GedcomIndividualsTree[$i][$this->_subTag($this->_GedcomIndividualsTree[$i]'DEAT''PLAC')]),
  306.                                                 @preg_replace('/\d SOUR (.*)/US',         '$1'$this->_GedcomIndividualsTree[$i][$this->_subTag($this->_GedcomIndividualsTree[$i]'DEAT''SOUR')]),
  307.                                                 @preg_replace('/\d NOTE (.*)/US',         '$1'$this->_GedcomIndividualsTree[$i][$this->_subTag($this->_GedcomIndividualsTree[$i]'DEAT''NOTE')]),
  308.                                                 @preg_replace('/\d SEX (\w)/US',          '$1'$this->_GedcomIndividualsTree[$i][$this->_tag($this->_GedcomIndividualsTree[$i]'SEX')]),
  309.                                                 @preg_replace('/\d OCCU (.*)/US',         '$1'$this->_GedcomIndividualsTree[$i][$this->_tag($this->_GedcomIndividualsTree[$i]'OCCU')]),
  310.                                                 @preg_replace('/\d SOUR (.*)/US',         '$1'$this->_GedcomIndividualsTree[$i][$this->_tag($this->_GedcomIndividualsTree[$i]'SOUR')]),
  311.                                                 @preg_replace('/\d OBJE @(O\d*)@/US',     '$1'$this->_GedcomIndividualsTree[$i][$this->_tag($this->_GedcomIndividualsTree[$i]'OBJE')]),
  312.                                                 $this->_arrayTag($this->_GedcomIndividualsTree[$i]'FAMS'),
  313.                                                 @preg_replace('/\d FAMC @(F\d*)@/US',     '$1'$this->_GedcomIndividualsTree[$i][$this->_tag($this->_GedcomIndividualsTree[$i]'FAMC')]),
  314.                                                 @preg_replace('/\d NATI (.*)/US',         '$1'$this->_GedcomIndividualsTree[$i][$this->_tag($this->_GedcomIndividualsTree[$i]'NATI')]),
  315.                                                 @preg_replace('/\d DATE (.*)/US',         '$1'$this->_GedcomIndividualsTree[$i][$this->_subTag($this->_GedcomIndividualsTree[$i]'FCOM''DATE')]),
  316.                                                 @preg_replace('/\d PLAC (.*)/US',         '$1'$this->_GedcomIndividualsTree[$i][$this->_subTag($this->_GedcomIndividualsTree[$i]'FCOM''PLAC')]),
  317.                                                 @preg_replace('/\d SOUR (.*)/US',         '$1'$this->_GedcomIndividualsTree[$i][$this->_subTag($this->_GedcomIndividualsTree[$i]'FCOM''SOUR')]),
  318.                                                 @preg_replace('/\d NOTE (.*)/US',         '$1'$this->_GedcomIndividualsTree[$i][$this->_subTag($this->_GedcomIndividualsTree[$i]'FCOM''NOTE')]),
  319.                                                 @preg_replace('/\d DATE (.*)/US',         '$1'$this->_GedcomIndividualsTree[$i][$this->_subTag($this->_GedcomIndividualsTree[$i]'BURI''DATE')]),
  320.                                                 @preg_replace('/\d PLAC (.*)/US',         '$1'$this->_GedcomIndividualsTree[$i][$this->_subTag($this->_GedcomIndividualsTree[$i]'BURI''PLAC')]),
  321.                                                 @preg_replace('/\d NOTE (.*)/US',         '$1'$this->_GedcomIndividualsTree[$i][$this->_tag($this->_GedcomIndividualsTree[$i]'NOTE')])
  322.                                                 );
  323.  
  324.             $this->GedcomIndividualsTreeObjects[=new Genealogy_Individual($Genealogy_Individual_Param);
  325.         }
  326.         unset($Genealogy_Individual_Param);
  327.   }
  328.  
  329.     /**
  330.      * Parse families tree
  331.      *
  332.      * Create an array of Genealogy_Family object
  333.      *
  334.      * @access private
  335.      */
  336.     function _parseFamilies({
  337.         for ($i=0; $i count($this->_GedcomFamiliesTree)$i++{
  338.             $Genealogy_Family_Param = array(@preg_replace('/0 @(F\d*)@ FAM/US',   '$1'$this->_GedcomFamiliesTree[$i][0]),
  339.                                             @preg_replace('/\d HUSB @(I\d*)@/US''$1'$this->_GedcomFamiliesTree[$i][$this->_tag($this->_GedcomFamiliesTree[$i],'HUSB')]),
  340.                                             @preg_replace('/\d WIFE @(I\d*)@/US''$1'$this->_GedcomFamiliesTree[$i][$this->_tag($this->_GedcomFamiliesTree[$i],'WIFE')]),
  341.                                             @preg_replace('/\d NCHI (.*)/US',     '$1'$this->_GedcomFamiliesTree[$i][$this->_tag($this->_GedcomFamiliesTree[$i],'NCHI')]),
  342.                                             $this->_arrayTag($this->_GedcomFamiliesTree[$i]'CHIL'),
  343.                                             @preg_replace('/\d DATE (.*)/US',     '$1'$this->_GedcomFamiliesTree[$i][$this->_subTag($this->_GedcomFamiliesTree[$i],'MARR''DATE')]),
  344.                                             @preg_replace('/\d TIME (.*)/US',     '$1'$this->_GedcomFamiliesTree[$i][$this->_subTag($this->_GedcomFamiliesTree[$i],'MARR''TIME')]),
  345.                                             @preg_replace('/\d PLAC (.*)/US',     '$1'$this->_GedcomFamiliesTree[$i][$this->_subTag($this->_GedcomFamiliesTree[$i],'MARR''PLAC')]),
  346.                                             $this->_arrayWitnessTag($this->_GedcomFamiliesTree[$i]),
  347.                                             $this->_contTag($this->_GedcomFamiliesTree[$i]'NOTE'),
  348.                                             @preg_replace('/\d SOUR (.*)/US',     '$1'$this->_GedcomFamiliesTree[$i][$this->_subTag($this->_GedcomFamiliesTree[$i],'MARR''SOUR')]),
  349.                                             array('Identifier'   => @preg_replace('/\d ASSO @(I\d*)@/US''$1'$this->_GedcomFamiliesTree[$i][$this->_tag($this->_GedcomFamiliesTree[$i]'ASSO')]),
  350.                                                   'Relationship' => @preg_replace('/\d RELA (.*)/US',     '$1'$this->_GedcomFamiliesTree[$i][$this->_subTag($this->_GedcomFamiliesTree[$i],'ASSO''RELA')])
  351.                                                   ),
  352.                                             @preg_replace('/\d DATE (.*)/US',     '$1'$this->_GedcomFamiliesTree[$i][$this->_subTag($this->_GedcomFamiliesTree[$i],'DIV''DATE')])
  353.                                             );
  354.  
  355.             $this->GedcomFamiliesTreeObjects[=new Genealogy_Family($Genealogy_Family_Param);
  356.         }
  357.         unset($Genealogy_Family_Param);
  358.     }
  359.  
  360.     /**
  361.      * Parse objects tree
  362.      *
  363.      * Create an array of Genealogy_Object object
  364.      *
  365.      * @access private
  366.      */
  367.     function _parseObjects(// IMGC -> Parentele
  368.         for ($i = 0; $i count($this->_GedcomObjectsTree)$i++{
  369.             $Genealogy_Object_Param = array(@preg_replace('/0 @(O\d*)@ OBJE/US''$1'$this->_GedcomObjectsTree[$i][0]),
  370.                                             @preg_replace('/\d FILE (.*)/US',    '$1'$this->_GedcomObjectsTree[$i][$this->_tag($this->_GedcomObjectsTree[$i],'FILE')])
  371.                                             );
  372.  
  373.             $this->GedcomObjectsTreeObjects[=new Genealogy_Object($Genealogy_Object_Param);
  374.         }
  375.         unset($Genealogy_Object_Param);
  376.     }
  377.  
  378.     /**
  379.      * Get subtag id
  380.      *
  381.      * @param  array   tree part
  382.      * @param  string  subtag
  383.      * @param  string  tag
  384.      * @return integer subtag id or nothing
  385.      * @access private
  386.      */
  387.     function _subTag($tab$mainTag$tag{
  388.         $i     $this->_tag($tab$mainTag);
  389.         $level $tab[$i]{0};
  390.  
  391.         for ($j=$i+1; $j count($tab)$j++{
  392.             if ($level $tab[$j]{0}{
  393.               if (@preg_match('/\d '.$tag.' (.*)/US'$tab[$j])) {
  394.                  return $j;
  395.               }
  396.             else {
  397.               return;
  398.             }
  399.         }
  400.     }
  401.  
  402.     /**
  403.      * Get tag id
  404.      *
  405.      * @param  array   tree part
  406.      * @param  string  tag
  407.      * @return integer tag id or 20 (force error)
  408.      * @access private
  409.      */
  410.     function _tag($tab$tag{
  411.         for ($i=0; $i count($tab)$i++{
  412.             if (@preg_match('/'.$tag.'/US'$tab[$i])) return $i;
  413.         }
  414.         return 20;
  415.     }
  416.  
  417.     /**
  418.      * Get tag contain with CONT
  419.      *
  420.      * @param  array  tree part
  421.      * @param  string tag
  422.      * @return string tag contain
  423.      * @access private
  424.      */
  425.     function _contTag($tab$mainTag{
  426.         $str   '';
  427.         $i     $this->_tag($tab$mainTag);
  428.         if ($i === 20{
  429.            return '';
  430.         }
  431.         $level = (integer) $tab[$i]{0};
  432.  
  433.         do {
  434.             // first line with main tag
  435.             if (@preg_match('/'.$mainTag.'/US'$tab[$i])) {
  436.               $str .= @preg_replace('/'.$level.' '.$mainTag.' (.*)/US''$1'$tab[$i]);
  437.               $i++;
  438.             }
  439.             // continue string with others CONT tag
  440.             if (isset($tab[$i]&& $level $tab[$i]{0}{
  441.               $str .= "\n".@preg_replace('/\d CONT (.*)/US''$1'$tab[$i]);
  442.               $i++;
  443.             else {
  444.               break;
  445.             }
  446.         while ($i count($tab));
  447.         return $str;
  448.     }
  449.  
  450.     /**
  451.      * Get an array of tags contains
  452.      *
  453.      * example for children (CHIL)
  454.      *
  455.      * @param  array  tree part
  456.      * @param  string tag
  457.      * @return array 
  458.      * @access private
  459.      */
  460.     function _arrayTag($tab$tag{
  461.         $arr = array();
  462.  
  463.         for ($i=0; $i count($tab)$i++{
  464.             if (@preg_match('/'.$tag.'/US'$tab[$i])) {
  465.                $arr[@preg_replace('/\d '.$tag.' @(.*)@/US''$1'$tab[$i]);
  466.             }
  467.         }
  468.         return $arr;
  469.     }
  470.     
  471.     /**
  472.      * Get Witness tags data
  473.      *
  474.      * @param  array  tree part
  475.      * @return array 
  476.      * @access private
  477.      */
  478.     function _arrayWitnessTag($tab{
  479.         $arr = array();
  480.         $k = 0;
  481.  
  482.         for ($i=$this->_tag($tab'WITN')$i count($tab)$i++{
  483.             if (@preg_match('/NAME/US'$tab[$i])) {
  484.               $arr[$k]['Name'trim(@preg_replace('/\d NAME (.*)\/(.*)\//US''$1 $2'$tab[$i]));
  485.             elseif (@preg_match('/TITL/US'$tab[$i])) {
  486.               $arr[$k]['Title'@preg_replace('/\d TITL (.*)/US''$1'$tab[$i]);
  487.             }
  488.             if (isset($arr[$k]['Name']&& isset($arr[$k]['Title'])) {
  489.                $k++;
  490.             }
  491.         }
  492.         return $arr;
  493.     }
  494. }
  495. ?>

Documentation generated on Mon, 11 Mar 2019 14:18:35 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.