PHP Libraries

by Kristoffe Brodeur.

All of this code works with PHP 5.x and Apache server on PC and Linux

00_findFileType_v2


<?php
//findJpgs by Kristoffe Brodeur
//04-07-2005
//10-16-2006 revised the checkDir and properly made name and ext to lowercase RENAME work and a return to the flash
//
//variables sent from FlashMX2004 ActionScript 2.0
//
//$folder:     where to look for pics
//$type:     filetype, jpgs in this example
//
//"files" is the variable sent back to FlashMX2004
//-----------------------------------------------
class FileList
     {
     var $actualfolder;
     var $rootDir;
     var $folderName;
     var $fileType;
     var $tempPtr;
     var $returnVar;
     var $fileNodes=array();
     //-----------------------------------------------
     function FileList($sentRootDir,$sentFolder,$sentFileType,$sentReturnVar)
          {
          $this->rootDir=$sentRootDir;
          $this->folderName=$sentFolder;
          $this->fileType=$sentFileType;
          $this->returnVar=$sentReturnVar;
          $this->checkDir();
          }//f(fileList)
     //-----------------------------------------------
     function checkDir()
          {
          $dir="";
          //echo("root:".$this->rootDir."<br>");
          //echo("folder:".$this->folderName."<br>");
          //echo("fileType:".$this->fileType."<br>");
          //
          if($this->rootDir!="")
               {
               $dir="./".$this->rootDir;
               //echo($dir);
               //
               if($this->folderName!="")
                    {
                    $dir=$dir."/".$this->folderName."/";
                    }
               else
                    {
                    $dir=$dir."/";
                    }
               }//if
          //
          else
               {
               //
               if($this->folderName!="")
                    {
                    $dir="./".$this->folderName."/";
                    }//if
               else
                    {
                    $dir="./".$this->rootDir."/";
                    }//else
               }//else
          
          //echo(">>>dir:".$dir);
          $this->actualFolder=$dir;
          $this->openDirectory($dir);
          }//f(checkDir)
     //-----------------------------------------------
     function openDirectory($sentFolder)
          {
          //
          if($pFolder=opendir($sentFolder))
               {
               //
               while(($file=readdir($pFolder))==true)
                    {
                    $this->tempPtr="";
                    $this->tempPtr=$this->findFileType($file,$this->fileType);
                    //echo("<BR>find:".$file.":".$this->tempPtr);
                    //
                    if($this->tempPtr!="")
                         {
                         $this->fileNodes[]=$this->tempPtr;
                         }//if
                    }//while
               $this->outputFilenames();
               }//if
          }//f(openDirectory)
     //-----------------------------------------------
     function findFileType($sentFilename,$sentFileType)
          {
          //$test[0]:filename
          //$test[1]:extension(uppercase/lowercase)test
          $thumbNameTest="";
          $oldName=explode('.',$sentFilename);
          //
          $nameToLower=strtolower($oldName[0]);
          $extToLower=strtolower($oldName[1]);
          //
          if($extToLower==$sentFileType)
               {
               $oldN=$this->actualFolder.$sentFilename;
               $newN=$this->actualFolder.$nameToLower.".".$extToLower;
               //added period "." with concentation ~.".".~
               if($nameToLower!=$oldName[0]||$nameToLower!=$oldName[1])
                    {
                    $noSpaces=str_replace(" ","^",$nameToLower);
                    //replace spaces with ^
                    if($noSpaces!=$nameToLower)
                         {
                         $newN=$noSpaces.".".$extToLower;
                         }                    
                    rename($oldN,$newN);
                    }
               //echo("[name]".$newN);
               return($nameToLower);
               //
               }//if
          }//f(findFileType)
     //-----------------------------------------------
     function outputFilenames()
          {
          echo("&".$this->returnVar."=");
          //
          for($a=0;$a<count($this->fileNodes)-1;$a++)
               {
               echo($this->fileNodes[$a].",");
               }//a
          echo($this->fileNodes[$a]);
          }//f(outputfilenames)
     //-----------------------------------------------
     }//class(fileList)
//-----------------------------------------------
$jpgs_Obj=new FileList($rootDir,$folder,$fileType,"files");
?>

00_findJpgs


<?php
//findJpgs by Kristoffe Brodeur 04-07-2005
//variables sent from FlashMX2004 ActionScript 2.0
//
//$folder: where to look for pics
//$type: filetype, jpgs in this example
//
//"files" is the variable sent back to FlashMX2004
//-----------------------------------------------
class FileList
     {
     var $actualfolder;
     var $rootDir;
     var $folderName;
     var $fileType;
     var $tempPtr;
     var $returnVar;
     var $fileNodes=array();
     //-----------------------------------------------
     function FileList($sentRootDir,$sentFolder,$sentFileType,$sentReturnVar)
          {
          $this->rootDir=$sentRootDir;
          $this->folderName=$sentFolder;
          $this->fileType=$sentFileType;
          $this->returnVar=$sentReturnVar;
          $this->checkDir();
          }//f(fileList)
     //-----------------------------------------------
     function checkDir()
          {
          //
          if($this->folderName!="")
               {
               $dir="./".$this->rootDir."/".$this->folderName."/";
               }//if
          //
          else
               {
               $dir="./".$this->rootDir;
               }//else
          $this->actualFolder=$dir;
          $this->openDirectory($dir);
          }//f(checkDir)
     //-----------------------------------------------
     function openDirectory($sentFolder)
          {
          //
          if($pFolder=opendir($sentFolder))
               {
               //
               while(($file=readdir($pFolder))==true)
                    {
                    $this->tempPtr="";
                    $this->tempPtr=$this->findFileType($file,$this->fileType);
                    //echo("<BR>find:".$file.":".$this->tempPtr);
                    //
                    if($this->tempPtr!="")
                         {
                         $this->fileNodes[]=$this->tempPtr;
                         }//if
                    }//while
               $this->outputFilenames();
               }//if
          }//f(openDirectory)
     //-----------------------------------------------
     function findFileType($sentFilename,$sentFileType)
          {
          //$test[0]:filename
          //$test[1]:extension(uppercase/lowercase)test
          $thumbNameTest="";
          $test=explode('.',$sentFilename);
          //
          $testUpperToLower=strtolower($test[1]);
          //
          if($testUpperToLower==$sentFileType)
               {
               //added period "." with concentation ~.".".~
               rename($this->actualFolder.$test[0].".".$this->fileType,$this->actualFolder.$test[0].".".$test[1]);
               $test[1]=$testUpperToLower;
               }//if
          //
          if($test[1]==$sentFileType)
               {
               $thumbNameTest=substr($test[0],0,2);
               $picNameWithSpaces=$test[0];
               $test[0]=str_replace(" ","^",$test[0]);
               //
               //echo("<br>tnT:".$thumbNameTest);
               if($thumbNameTest!="t_"&&$thumbNameTest!="T_")
                    {
                    return($test[0]);
                    }//if
               }//if
          }//f(findFileType)
     //-----------------------------------------------
     function outputFilenames()
          {
          echo("&".$this->returnVar."=");
          //
          for($a=0;$a<count($this->fileNodes)-1;$a++)
               {
               echo($this->fileNodes[$a].",");
               }//a
          echo($this->fileNodes[$a]);
          }//f(outputfilenames)
     //-----------------------------------------------
     }//class(fileList)
//-----------------------------------------------
$jpgs_Obj=new FileList($rootDir,$folder,"jpg","files");
?>

associative_pointers


<?php
//04-08-2008
//associative pointers for nodes test 1.0 by kristoffe brodeur.
//-----
Class Node
{
var $name; //node name
var $data; //text data
//-----
function Node($sName,$sText)
{
$this->name=$sName;
//
if($sText!="")
{
$this->data=$sText;
}
else
{
$this->data="-"; //I hate empty nodes
}
//
}
}
//-----
function AddNode($tgtPar,$sName,$sText)
{
//
if(!$tgtPar->{$sName})
{
echo "<br />new array node [".$sName."]";
$tgtPar->{$sName}=array();
}
$ptr=count($tgtPar->{$sName});
$tgtPar->{$sName}[$ptr]=new Node($sName,$sText);
}
//-----
Class NodeArray
{
//-----
function NodeArray()
{
echo "<br />NodeArray<br />";
//$this->{$sRootNode}=new Node($sRootNode);
}
}
//-----
$testArray=new NodeArray();
$nodes=array("state","city","town","street");
print_r($nodes);
//AddNode($testArray,$nodes[0]);
//echo "<br />[node]".$testArray->state[0]->name;
$cnt=count($nodes);
echo $cnt;
//
for($a1=0;$a1<$cnt;$a1++)
{
//
if($a1==0)
{
echo "<br />0";
$ptr=$testArray;
}
else
{
//we are pointing to the node before the current one we want to add to
$ptr=$ptr->{$nodes[$a1-1]};
$nodeCt=count($ptr);
//we are counting the amount of nodes in the array minus 1, because the count starts at 1, while nodes start at 0
$ptr=$ptr[$nodeCt-1];
}
AddNode($ptr,$nodes[$a1]);
$tCnt=count($ptr->{$nodes[$a1]});
echo "<br/>".$ptr->{$nodes[$a1]}[$tCnt-1]->name;
}
echo "<br />ready to test nodes";
echo "<br/>city test:".$testArray->state[0]->city[0]->name;
echo "<br/>town test:".$testArray->state[0]->city[0]->town[0]->name;
echo "<br/>street test:".$testArray->state[0]->city[0]->town[0]->street[0]->name;
?>

build_menu


<?php
/*
build_menu.php v1.0 by Kristoffe Brodeur. ©2010 All Rights Reserved.
02-20-2010
*/
//-----
Class tableNode
     {
     function __construct()
          {
          }
     }
//-----
$to_root="../../";
require '_info.php';
require 'settings.php';
echo "building the dropown menus from the mysql data<hr />";
$connect=mysql_connect($server,$user,$pass)or die("Error, login to $server failed. <span class='error'>".mysql_error()."</span>");
$selDB=mysql_select_db($db)or die("Could not select database $db: <span class='error'>".mysql_error()."</span>");
//-----ourwork (B|D)
$str_ourwork="";
$tableSect="ourwork";
$linkS=mysql_query("SELECT * FROM $tableSect");
$lenS=mysql_num_rows($linkS);
$arrS=array();
//
for($s=0;$s<$lenS;$s++)
     {
     $arrS[$s]=new tableNode();
     $arrS[$s]->row=mysql_fetch_assoc($linkS);
     $sStr=$arrS[$s]->row['section'];
     $nName="a2b".($s+1);
     $str_ourwork.= '
     [div class="B" id="f'.($s+1).'" onclick="change_work(this,'.$s.');"]
          [a href="mS/work/area.php?id='.($s+1).'" onClick="doSomething();return false" id="'.$nName.'_"]'.$sStr.'[/a][/div]<br />
     [div class="B" id="'.$nName.'"]<br />';
     //
     $tableEx="work_".$arrS[$s]->row['folder'];
     $linkN=mysql_query("SELECT * FROM $tableEx");
     $lenN=mysql_num_rows($linkN);
     $arrS[$s]->arrN=array();
     //examples
     for($n=0;$n<$lenN;$n++)
          {
          $arrS[$s]->arrN[$n]=mysql_fetch_assoc($linkN);
          $nStr=$arrS[$s]->arrN[$n]['title'];          
          $nName="a2b".($s+1)."c".($n+1);
          $str_ourwork.= '
          [div class="D" id="'.$nName.'" onClick="changeEx(this,'.($n+1).');return false"]
               [a href="mS/work/subarea.php?id='.($n+1).'" onClick="doSomething();return false" id="'.$nName.'_"]'.$nStr.'[/a][/div]<br />';
          }
     $str_ourwork.='[/div]<br />';
     }
//-----our_team
$str_ourteam="";
$tableBios="bios";
$linkB=mysql_query("SELECT * FROM $tableBios");
$lenB=mysql_num_rows($linkB);
$arrB=array();
//
for($b=0;$b<$lenB;$b++)
     {
     $arrB[$b]=new tableNode();
     $arrB[$b]->row=mysql_fetch_assoc($linkB);
     $bStr=$arrB[$b]->row['name'];
     $str_ourteam.='[div class="C" onClick="change_bio(this,'.($b+1).')" id="a1b3c'.($b+1).'"][a href="our_team.php?id='.($b+1).'" id="a1b3c'.($b+1).'_" onClick="doSomething();return false"]'.$bStr.'[/a][/div]<br />';     
     }
//-----alliances
$str_alliances="";
$tableAlliances="alliances";
$linkA=mysql_query("SELECT * FROM $tableAlliances");
$lenA=mysql_num_rows($linkA);
$arrA=array();
//
for($a=0;$a<$lenA;$a++)
     {
     $arrA[$a]=new tableNode();
     $arrA[$a]->row=mysql_fetch_assoc($linkA);
     $aStr=$arrA[$a]->row['name'];
     //onClick="doSomething();return false"
     $str_alliances.='[div class="C" id="a1b4c'.($a+1).'" onClick="change_alliance(this,'.($a+1).');return false"][a onClick="doSomething();return false" href="alliances.php?id='.($a+1).'" id="a1b4c'.($a+1).'_"]'.$aStr.'[/a][/div]<br />';     
     }
//-----our_company (B...)
$strCMP="Client Experience:client.php,Our Services:services.php,Our Team:our_team.php,Alliances:alliances.php";
$arrCMP=explode(",",$strCMP);
$lenC=count($arrCMP);
$arrC=array();
$str_comp="";
//
for($c=0;$c<$lenC;$c++)
     {
     $tmpC=explode(":",$arrCMP[$c]);
     $arrC[$c]=new tableNode();
     $arrC[$c]->row=array();
     $arrC[$c]->row['title']=$tmpC[0];
     $middle="";
     $md="";
     $oC="";
     $id="a1b".($c+1);
     //
     switch($c)
          {
          case(0):
               break;
          case(1):
               break;
          //our_team
          case(2):
               $middle=$str_ourteam;
               //$md='onmousedown="test(\'a1b'.($c+1).'\');"';
               //$onC='onClick="doSomething();return false"';
               break;
          //alliances
          case(3):
               $middle=$str_alliances;
               //$md='onmousedown="test(\'a1b'.($c+1).'\');"';
               //$onC='onClick="doSomething();return false"';
               break;
          }
     $str_comp.='[div class="B" '.$md.'][a href="'.$tmpC[1].'" '.$onC.' id="'.$id.'_"]'.$tmpC[0].'[/a][/div]<br />';
     $str_comp.='[div class="B" id="'.$id.'"]<br />';
     $str_comp.=$middle;
     $str_comp.="---------------[/div]<br />";
     }
//-----main areas (A)
$strVMA="OUR COMPANY:company.php?home=-1,OUR WORK:our_work.php,CONTACT US:contact.php";
$arrVMA=explode(",",$strVMA);
$lenM=count($arrVMA);
$arrM=array();
$str_main="";
//
for($m=0;$m<$lenM;$m++)
     {
     $tmpM=explode(":",$arrVMA[$m]);
     $arrM[$m]=new tableNode();
     $arrM[$m]->row=array();
     $arrM[$m]->row['title']=$tmpM[0];
     $middle="";
     $id="a".($m+1);
     //
     switch($m)
          {
          case 0:
               $middle=$str_comp;
               break;
          case 1:
               $middle=$str_ourwork;
               break;
          case 2:
               //$md='onmousedown="test(\'a'.($m+1).'\');"';
               //$oC='onClick="doSomething();return false"';
               break;
          }
     $str_main.='
     [div class="A" '.$md.'][a href="'.$tmpM[1].'" '.$oC.' id="'.$id.'_"]'.$tmpM[0].'[/a][/div]<br />
     [div class="A" id="'.$id.'"]<br />';
     $str_main.=$middle;
     $str_main.='[/div]<br />';
     }
//-----
mysql_close($connect);
//echo $str_main;
$view=array("[","]","-","<br />");
$output=array("<",">","","\n");
$str_mainHTML=str_replace($view,$output,$str_main);
echo $str_mainHTML;
$file=fopen($to_root."menus/dynamic_menu.html","w");
fwrite($file,$str_mainHTML);
fclose($file);
?>
<SCRIPT LANGUAGE="JavaScript" type="text/javascript">
location.href="<?php echo $to_root;?>mach/ttf-mainmenu_creator.php";
</SCRIPT>

display_php


<?php
//04-07-2008
//code formatting for PHP output to html by kristoffe brodeur. (c)2008 all rights reserved
//$filename="../*.php";
echo("[filename]".$filename);
echo("<br/>©2008 by Kristoffe Brodeur. All Rights Reserved.<br/><br/>");
$fp = @fopen($filename, 'r');
//
if($fp)
     {
     $str=fread($fp,filesize($filename));
     $arr1=explode("\n",$str);
     //
     for($a=0;$a<count($arr1);$a++)
          {
          $orig1=array(
               "<",
               ">",
               "\t",
               "function",
               "class",
               "Class");
          $replace1=array(
               "<",
               ">",
               "     ",
               "<font color='#FF0000'><b>function</b></font>",
               "<font color='#FF0000'><b>Class</b></font>",
               "<font color='#FF0000'><b>Class</b></font>",
               );
          $c=str_replace($orig1,$replace1,$arr1[$a]);
          echo("<br/> $c");
          }
     }
?>

fileRoutines


<?php
/*
fileRoutines.php v1.0 by Kristoffe Brodeur. ©2010 All Rights Reserved.
02-16-2010 php file and folder routines
02-29-2010 added readFile
*/
//-----
function delTree($path)
     {
     echo "+$path<br />";
     //
     if($handle=opendir($path))
          {
          //
          while(false !== ($file=readdir($handle)))
               {
               //
               if($file!="."&&$file!="..")
                    {
                    $dirTest=$path.$file."/";
                    //
                    if(is_dir($dirTest))
                         {
                         delTree($dirTest);
                         rmdir($path.$file);     //rmdir for a folder, unlink for a file               
                         }
                    else
                         {
                         unlink($path.$file);
                         echo "$path.$file<br />";
                         }
                    }
               }
          }
     }
//-----
function readMyFile($link)
     {
     $str="";
     //
     if(file_exists($link))
          {
          $handle=@fopen($link,"r");
          //
          while(!feof($handle))
               {
               $str.=fgets($handle,4096);
               }
          }
     return $str;
     }
?>

find_fileCount


<?php
/*
find_fileCount.php v2.0 by Kristoffe Brodeur. ©2010 All Rights Reserved.
01-05-2009 stripped from other PHP programs I've written, modified for the gallery flash module
*/
//-----
function find_fileCount($sFolder,$sFileType)
{
$fAmt=0;
//
$dir=$sFolder;
//echo "<br/>finding files in $dir ...";
$pFiles=opendir($dir);
//
while(($file=readdir($pFiles))==true)
{
$thTest=substr($file,0,1);//if a jpg is a thumbnail, discard it in the image count
$extChk=substr($file,-3);
$jpg=false;
//echo $extChk."<br />";
if($extChk==$sFileType){$jpg=true;}
//
if($file!="."&&$file!=".."&&$thTest!="~"&&$jpg==true)
{
//echo $file;
$lwr=strtolower($file);
//echo " ~ ".$lwr;
//
if($file!=$lwr)
{
//echo "[>lwr]$file";
//rename to ~ + filename, and then filename lowercase (windows bug)
//rename($dir.'/'.$file,$dir.'/~'.$file);
//rename($dir.'/~'.$file,$dir.'/'.$lwr);
}
$fAmt++;
}
}
//echo ':'.$fAmt;
return($fAmt);
}
//-----
$ready=false;
$type="_POST";
//
if(isset(${$type}['folder']))
     {
     $ready=true;
     $folder=${$type}['folder'];
     //
     if(isset(${$type}['ext']))
          {
          $ready=true;
          $ext=${$type}['ext'];
          }
     else
          {
          $ready=false;
          }
     }
//
if($ready==true)
     {
     $found=find_fileCount($folder,$ext);
     echo "&count=".$found;//back to flash
     }
else
     {
     echo "&count=-1";//error variables not set in flash POST request
     }
?>

find_files


<?php
/*
find_files v2.1 by Kristoffe Brodeur for PHP include libraries. ©2009 All rights reserved.
04-07-2009 first standalone version
10-30-2009 added a restriction option to not load thumbnails, etc
-if there are no file restrictions, just send "" as the $sRestr when creating a new 'find_files'
*/
//-----
class find_files
{
var $sFldr;
var $sType;
var $files;
//-----
function __construct($sFldr,$sType,$sRestr)
{
$aa=opendir($sFldr);
$this->files=array();
//
while(($file=readdir($aa))==true)
{
//
if(strlen($file)>4)
{
$extLen=strlen($sType);
     $extChk=substr($file,-$extLen);
     $restrChk="";
     $restrFlag=false;
     //
     if($sRestr!="")
          {
          $restrLen=strlen($sRestr);
          $restrChk=substr($file,0,$restrLen);
          //
          if($sRestr==$restrChk)
               {
               $restrFlag=true;
               }
          }
//
if(($extChk==$sType)&&($restrFlag==false))
{
$sLen=strlen($file);
$justFile=substr($file,0,$sLen-$extLen-1);
$this->files[]=$justFile;
}
}
}
}
}
?>

find_firstFile


<?php
/*
find_firstFile.php by Kristoffe Brodeur. ©2010 All Rights Reserved.
01-05-2009 just modified fined_fileCount.php to look for the first file with the proper extension, mostly for thumbnails in folders
*/
//-----
function find_firstFile($sFolder,$sFileType)
{
$fAmt=0;
//
$dir=$sFolder;
//echo "<br/>finding first file in $dir ...";
$pFiles=opendir($dir);
$found=false;
$fName="-1";
//
while((($file=readdir($pFiles))==true)&&($found==false))
{
$thTest=substr($file,0,1);//if a jpg is a thumbnail, discard it in the image count
$extChk=substr($file,-3);
$jpg=false;
//echo $extChk."<br />";
if($extChk==$sFileType){$jpg=true;}
//
if(($file!=".")&&($file!="..")&&($thTest!="~")&&($jpg==true))
          {
          $found=true;
          $lwr=strtolower($file);
          //echo "[file]$file<br />";
          //echo " ~ ".$lwr;
          //
          if($file!=$lwr)
               {
               //echo "[>lwr]$file";
               //rename to ~ + filename, and then filename lowercase (windows bug)
               //rename($dir.'/'.$file,$dir.'/~'.$file);
               //rename($dir.'/~'.$file,$dir.'/'.$lwr);
               }
          $len=strlen($file);
          $fName=substr($lwr,0,$len-4);
          //echo "[$fName]";
          }
     }
return($fName);
}
//-----
$type="_POST";//test from flash with _GET or _POST
$ready=false;
if(isset(${$type}['folder']))
     {
     $ready=true;
     $folder=${$type}['folder'];
     //
     if(isset(${$type}['ext']))
          {
          $ready=true;
          $ext=${$type}['ext'];
          }
     else
          {
          $ready=false;
          }
     }
//
if($ready==true)
     {
     $fName=find_firstFile($folder,$ext);
     echo "&fName=".$fName;//back to flash
     }
else
     {
     echo "&fName=-1";//error variables not set in flash POST request
     }
?>

find_fType


<?php
//findJpgs by Kristoffe Brodeur 04-07-2005:10-12-05
//revision 09-27-2005 : fixed checkDir()
//variables sent from FlashMX2004 ActionScript 2.0
//
//$folder: where to look for pics
//$type: filetype, jpgs in this example
//
//"files" is the variable sent back to FlashMX2004
//----------
//
//----------
//echo("findFileType_v3.php");
$test=new FileList("./","as","files");
//----------
class FileList
     {
     var $actualfolder;
     var $Dir;
     var $fileType;
     var $fChk;
     var $returnVar;
     var $fileNodes=array();
     //----------
     function FileList($sentDir,$sentFileType,$sentReturnVar)
          {
          //echo("<br>[FileList]<br>");
          $this->Dir=$sentDir;
          $this->fileType=$sentFileType;
          $this->returnVar=$sentReturnVar;
          $this->openDirectory();
          }//f(fileList)
     //----------
     function openDirectory()
          {
          //
          if($pFolder=opendir($this->Dir))
               {
               //
               while(($file=readdir($pFolder))==true)
                    {
                    $this->fChk="";
                    $this->fChk=$this->findFileType($file,$this->fileType);
                    //
                    if($this->fChk!="0")
                         {
                         //echo("<br/>".$this->fChk);
                         $this->fileNodes[]=$this->fChk;
                         }
                    //
                    }//while
               $this->outputFilenames();
               }//if
          }//f(openDirectory)
     //----------
     function findFileType($sFName,$sFType)
          {
          $test=explode('.',$sFName);
          $tEnd="";
          //
          if(count($test)>1)
               {
               $aEnd=strtolower($test[1]);
               //
               if($aEnd==$sFType)
                    {return($test[0]);}               
               //
               else
                    {return("0");}
               }
          //
          else
               {return("0");}
          }
     //----------
     function outputFilenames()
          {
          //echo("&".$this->returnVar."=");
          //
          for($a=0;$a<count($this->fileNodes)-1;$a++)
               {
               //echo($this->fileNodes[$a].",");
               }//a
          //echo($this->fileNodes[$a]);
          }//f(outputfilenames)
     //----------
     }//class(fileList)
//----------
?>

flash-col_allRows


<?php
/*
flash-col_allRows.php v1.0 by Kristoffe Brodeur. ©2010 All Rights Reserved.
02-21-2010
*/
//
if(isset($_POST['table']))
     {
     $table=$_POST['table'];
     $col=$_POST['col'];
     }
$to_root="../";
require $to_root.'mS/admin/_info.php';
require $to_root.'mS/admin/settings.php';
$connect=mysql_connect($server,$user,$pass)or die("Error, login to $server failed. <span class='error'>".mysql_error()."</span>");
$selDB=mysql_select_db($db)or die("Could not select database $db: <span class='error'>".mysql_error()."</span>");
$query="SELECT * FROM $table";
$link=mysql_query($query)or die(mysql_error());
$len=mysql_num_rows($link);
echo $len;
$output="";
//
for($a=0;$a<$len-1;$a++)
     {
     $row=mysql_fetch_array($link);
     $output.=str_replace("&","^",$row[$col])."`";
     }
$row=mysql_fetch_array($link);
$output.=str_replace("&","^",$row[$col]);
mysql_close($connect);
echo "?success=true&output=".$output;
?>

flash-num_rows


<?php
/*
flash-num_rows.php v1.0 by Kristoffe Brodeur. ©2010 All Rights Reserved.
02-21-2010
*/
//
if(isset($_POST['table']))
     {
     $table=$_POST['table'];
     }
$to_root="../";
require $to_root.'mS/admin/_info.php';
require $to_root.'mS/admin/settings.php';
$connect=mysql_connect($server,$user,$pass)or die("Error, login to $server failed. <span class='error'>".mysql_error()."</span>");
$selDB=mysql_select_db($db)or die("Could not select database $db: <span class='error'>".mysql_error()."</span>");
$query="SELECT * FROM $table";
$link=mysql_query($query)or die(mysql_error());
$count=mysql_num_rows($link);
mysql_close($connect);
echo "?success=true&count=".$count;
?>

flashToString


<?php
//
function flashToString($swf,$swfW,$swfH)
     {
     $str='
     <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="'.$swfW.'" height="'.$swfH.'">
          <param name="movie" value="'.$swf.'" />
          <param name="quality" value="high" />
          <embed src="'.$swf.'" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="'.$swfW.'" height="'.$swfH.'"></embed>
     </object>';
     return $str;
     }
?>

flash_query


<?php
/*
flash_query.php v1.0 by Kristoffe Brodeur. ©2010 All Rights Reserved.
02-18-2010
*/
//-----string comma delineated from LoadVars 'cols' for the desired return columns from the table row
//
if(isset($_POST['cols']))
     {
     $cols=explode(",",$_POST['cols']);
     $lenC=count($cols);
     //
     foreach($cols as $val)
          {
          echo "[*]$val<br />";
          }
     }
//
$vars="table,id";
$varArr=explode(",",$vars);
$len=count($varArr);
//
for($a=0;$a<$len;$a++)
     {
     //
     if(isset($_POST["{$varArr[$a]}"]))
          {
          ${$varArr[$a]}=$_POST["{$varArr[$a]}"];
          //echo $varArr[$a]."=".$_POST["{$varArr[$a]}"]."<br />";
          }
     }
$colsOut="";
$to_root="../";
require $to_root.'mS/admin/_info.php';
require $to_root.'mS/admin/settings.php';
require $to_root.'php/mysql_functions.php';
$connect=mysql_connect($server,$user,$pass)or die("Error, login to $server failed. <span class='error'>".mysql_error()."</span>");
$selDB=mysql_select_db($db)or die("Could not select database $db: <span class='error'>".mysql_error()."</span>");
$query="SELECT * FROM $table WHERE id=$id";
echo "$query<br />";
$link=mysql_query($query)or die(mysql_error());
$rowQC=mysql_fetch_assoc($link);
//
$lenQC=count($rowQC);
//
foreach($rowQC as $key=>$val)
     {
     //echo "$key | $val<br />";
     //
     for($a=0;$a<$lenC;$a++)
          {
          $val=str_replace("&","^",$val);
          $val=str_replace("+","~",$val);
          //
          if($key==$cols[$a])
               {
               $colsOut.="&".$key."=".$val;
               }
          }
     }
mysql_close($connect);
echo $colsOut;
?>

format_code


<?php
/*
06-17-2010
code formatting for PHP output to html by kristoffe brodeur. ©2010 all rights reserved
$filename="../*.php";
*/
function format_code($filename)
     {
     $fp = fopen($filename, 'r');
     //
     if($fp)
          {
          $str=fread($fp,filesize($filename));
          fclose($fp);
          $arr1=explode("\n",$str);
          //
          for($a=0;$a<count($arr1);$a++)
               {
               $orig1=array(
                    "#",
                    "\"",
                    "<",
                    ">",
                    "\t",
                    );
               $replace1=array(
                    "&#35;",
                    "\"",
                    "<",
                    ">",
                    "     ",
                    );
                    
               $c.="<br />".str_replace($orig1,$replace1,$arr1[$a]);
               }
          }
     return $c;
     }
?>

f_filetype_as2


<?php
//10-22-2007
//07-21-2008 come minor code testing and cleanup
//03-14-2009 works without regsiter_globals now
//f_filetype_as.php 2.0 by Kristoffe Brodeur. Copyright 2007 All Rights Reserved.
//-----
function main($sFldr,$sFType)
{
$ext=$sFType;
$files=array();
//echo('ok...');
$pFiles=opendir($sFldr);
//
while(($file=readdir($pFiles))==true)
{
//
if(strlen($file)>4)
{
//echo('<br/>'.$file);
$extChk=substr($file,-3);
$thChk=substr($file,0,1);//is there a ~ meaning thumbnail? skip
//echo "<br />".$extChk.":".$thChk;
//
if($extChk==$ext&&$thChk!="~")
{
$sLen=strlen($file);//how long is the filename
$smaller=substr($file,0,$sLen-4);//take off .jpg, save 4 characters per filename to transfer (20~40 percent savings in transfer)
$files[count($files)]=$smaller;
//echo "<br />?:".$files[count($files)];
$fTest=$sFldr.$file;
}
}
}
$cnt1=count($files)-1;//loop until -1 of names for *name* and , 1,2,3,4,5,
echo '&files=';
//
for($a=0;$a<$cnt1;$a++)
{
echo $files[$a].',';
}
echo $files[$a];
}
//-----
//register_globals=off fix
//$_GET for flash send
//$_POST instead for flash sendAndLoad
$fldr=$_POST['fldr'];
$fType=$_POST['fType'];
//echo $fldr.'<br />'.$fType;
//
main($fldr,$fType);
//main("pics/09_29_2007");
?>

generic_parser_beta


<?php
//04-07-2008
//generic xml parser to associate arrays by kristoffe brodeur.
//v1.0
Class XML_parse
{
var $fName; //the filename of the XML file to be read and parsed
var $depth; //the index depth of the current ndoe in the XML file structure
var $nest; //string array holding the current node names of the family tree point being read
var $nodes; //where the associate array is created with Class NodeArray, Class Node, and (f)addNode
var $XML; //XML node associative array
var $tgt;
//-----
function XML_parse($sFName)
{
//holds the nest of node names and family tree to push and pop for associative node creation
$this->nest=array();
$this->depth=-1;
$this->fName=$sFName;
$this->XML=new NodeArray();
//
if(!($this->xmlparser=xml_parser_create()))
{die("Cannot create parser.");}
//
else
{echo "Xml parser created!<br />";}
//only inside of a class is this needed
xml_set_object($this->xmlparser,$this);
xml_set_element_handler($this->xmlparser,"start_tag","end_tag");
xml_set_character_data_handler($this->xmlparser,"tag_contents");
//
if(!($fp=fopen($this->fName,"r")))
{die("cannot open ".$this->fname);}
//
while($data=fread($fp,4096))
{
//find any > < and replace with >< getting rid of spaces and newlines etc.
$data=eregi_replace(">"."[[:space:]]+"."<","><",$data);
//
if(!xml_parse($this->xmlparser,$data,feof($fp)))
{
$reason=xml_error_string(xml_get_error_code($this->xmlparser));
$reason.=xml_get_current_line_number($this->xmlparser);
die($reason);
}
}
echo "done";
}
//-----
function addCurrData($sData)
{
$pNode=$this->XML;
echo "<br />[addCurrData]<br />";
$cnt=count($this->nest);
//
for($a1=0;$a1<$cnt;$a1++)
{
$ptr=$this->nest[$a1];
$pNodeCnt=count($pNode->{$ptr});
$pNode=$pNode->{$ptr}[$pNodeCnt-1];
echo "^[".$ptr."]^".$pNode->ID;
}
echo $sData."<br />";
$pNode->DATA=$sData;
echo "<br />".$pNode->DATA;
}
//-----
function createNode($sNode)
{
$pNode=$this->XML;
//
if($this->depth==0)
{
echo "<br />=zero=";
}
//i need a loop to count each parent node's amount, point to it, and then goto the next child, count, etc, and then add the new node
else
{
//how many nodes are we up to so far?
$cnt=count($this->nest);
//we are preparing the route for the child, so we only need the par(root)
for($a1=0;$a1<$cnt-1;$a1++)
{
$ptr=$this->nest[$a1];//keep adding the node name to use associatively
$pNodeCnt=count($pNode->{$ptr});//how many nodes are in that associative array (security[0],security[1],etc...)?
$pNode=$pNode->{$ptr}[$pNodeCnt-1];//the node to attach this new node child is the path, array # by count of it -1 (arrays start at 0)
}
}
AddNode($pNode,$sNode);
$pCnt=count($pNode->{$sNode});
//count-1 is where node0 is for the 1st node, nodes 0,1=count 1,2
//echo "<br />[name]".$pNode->{$sNode}[$pCnt-1]->name;
// echo"<br />-----<br />";
}
//-----
function start_tag($parser,$name,$attribs)
{
$lNode=strtolower($name);
//create the child node, then increase the depth for proper pointing of nodes
$this->depth++;
array_push($this->nest,$lNode);
$this->createNode($lNode);
$cnt=count($attribs);
//for now, to simplify the reader and creator, ill omit any node attribs
$tab=$this->tabit($this->depth);
echo "<br />".$this->depth.$tab."<".$lNode.">";//.":".$attribs;
//
}
//-----
function end_tag($parser,$name)
{
$tab=$this->tabit($this->depth);
$lNode=strtolower($name);
echo "<br />".$this->depth.$tab."<".'/'.$lNode.">";
//$viz=$this->showNest();
//pop the last node that is finished after echoing it to output
$this->depth--;
array_pop($this->nest);
}
//-----
function tag_contents($parser,$data)
{
$this->addCurrData($data);
echo $data;
}
//-----
function showNest()
{
$nL=count($this->nest);
//
for($a1=0;$a1<$nL;$a1++)
{
echo "[".$this->nest[$a1]."]";
}
}
//-----
function tabit($amt)
{
$str="";
$chr="   ";
//
for($a1=0;$a1<$amt;$a1++)
{
$str.=$chr;
}
return $str;
}
}
//-----
Class Node
{
var $ID; //node name
var $DATA; //text data
//-----
function Node($sID,$sText)
{
$this->ID=$sID;
//
if($sText!="")
{
$this->DATA=$sText;
}
else
{
$this->DATA="-"; //I hate empty nodes
}
//
}
}
//-----
function AddNode($tgtPar,$sName,$sText)
{
echo "<br />[AddNode]".$sName;
//
if(!$tgtPar->{$sName})
{
$tgtPar->{$sName}=array();
}
$ptr=count($tgtPar->{$sName});
$tgtPar->{$sName}[$ptr]=new Node($sName,$sText);
}
//-----
Class NodeArray
{
//-----
function NodeArray($sRootNode)
{
echo "<br />NodeArray ".$sRootNode."<br />";
//$this->{$sRootNode}=new Node($sRootNode);
}
}
//-----
//-----
//-----
$filename="plist.xml";
$events=new XML_parse($filename);
echo "<br />Testing final parsing...<br />";
$cnt=count($events->XML->people[0]->person);
echo "<br />*person 0:".$events->XML->people[0]->person[0]->address[0]->ID."*";
echo "<br />*person 1:".$events->XML->people[0]->person[1]->address[0]->ID."*";
echo "<br />*person 1:".$events->XML->people[0]->person[1]->address[0]->DATA."*";
?>

generic_parser_compact


<?php
//04-07-2008 COMPACT VERSION
//generic xml parser to associate arrays by kristoffe brodeur.
//v1.0
Class XML_parse
{
var $fName;
var $depth;
var $nest;
var $nodes;
var $XML;
var $tgt;
function XML_parse($sFName)
{
$this->nest=array();
$this->depth=-1;
$this->fName=$sFName;
$this->XML=new NodeArray();
if(!($this->xmlparser=xml_parser_create())){die("Cannot create parser.");}
else{echo "Xml parser created!<br />";}
xml_set_object($this->xmlparser,$this);
xml_set_element_handler($this->xmlparser,"start_tag","end_tag");
xml_set_character_data_handler($this->xmlparser,"tag_contents");
if(!($fp=fopen($this->fName,"r"))){die("cannot open ".$this->fname);}
while($data=fread($fp,4096))
{
$data=eregi_replace(">"."[[:space:]]+"."<","><",$data);
if(!xml_parse($this->xmlparser,$data,feof($fp)))
{
$reason=xml_error_string(xml_get_error_code($this->xmlparser));
$reason.=xml_get_current_line_number($this->xmlparser);
die($reason);
}
}
}
function addCurrData($sData)
{
$pNode=$this->XML;
$cnt=count($this->nest);
for($a1=0;$a1<$cnt;$a1++)
{
$ptr=$this->nest[$a1];
$pNodeCnt=count($pNode->{$ptr});
$pNode=$pNode->{$ptr}[$pNodeCnt-1];
}
$pNode->DATA=$sData;
}
function createNode($sNode)
{
$pNode=$this->XML;
if($this->depth==0){}
else
{
$cnt=count($this->nest);
for($a1=0;$a1<$cnt-1;$a1++)
{
$ptr=$this->nest[$a1];
$pNodeCnt=count($pNode->{$ptr});
$pNode=$pNode->{$ptr}[$pNodeCnt-1];
}
}
AddNode($pNode,$sNode);
$pCnt=count($pNode->{$sNode});
}
function start_tag($parser,$name,$attribs)
{
$lNode=strtolower($name);
$this->depth++;
array_push($this->nest,$lNode);
$this->createNode($lNode);
$cnt=count($attribs);
$tab=$this->tabit($this->depth);
}
function end_tag($parser,$name)
{
$tab=$this->tabit($this->depth);
$lNode=strtolower($name);
$this->depth--;
array_pop($this->nest);
}
function tag_contents($parser,$data)
{
$this->addCurrData($data);
echo $data;
}
function showNest()
{
$nL=count($this->nest);
for($a1=0;$a1<$nL;$a1++){echo "[".$this->nest[$a1]."]";}
}
function tabit($amt)
{
$str="";
$chr="   ";
for($a1=0;$a1<$amt;$a1++){$str.=$chr;}
return $str;
}
}
Class Node
{
var $ID;
var $DATA;
function Node($sID,$sText)
{
$this->ID=$sID;
if($sText!=""){$this->DATA=$sText;}
else{$this->DATA="-";}
}
}
function AddNode($tgtPar,$sName,$sText)
{
if(!$tgtPar->{$sName}){$tgtPar->{$sName}=array();}
$ptr=count($tgtPar->{$sName});
$tgtPar->{$sName}[$ptr]=new Node($sName,$sText);
}
Class NodeArray
{
function NodeArray($sRootNode){}
}
//-----
$filename="plist.xml";
$events=new XML_parse($filename);
echo "<br />Testing final parsing...<br />";
$cnt=count($events->XML->people[0]->person);
echo "<br />*person 0:".$events->XML->people[0]->person[0]->address[0]->ID."*";
echo "<br />*person 1:".$events->XML->people[0]->person[1]->address[0]->ID."*";
echo "<br />*person 1:".$events->XML->people[0]->person[1]->address[0]->DATA."*";
?>

include_php_test1


<?php
//using external php files by Kristoffe Brodeur. (c)2007 All rights reserved.
//v1.0 03-15-2007
include ("../../../find_fType.php");
$sDir="./php/";
$sFType="php";
$testXXX=new FileList($sDir,$sFType,"files");
echo("<b>Actionscript Library</b><br/>Right Click Icon to Save as...<br />Left click filename to view code.");
//
display_as($testXXX->fileNodes,$sFType,$sDir);
//
function display_as($sentArray,$sFType,$sDir)
     {
     //
     for($a1=0;$a1<count($sentArray);$a1++)
          {
          $disp=$sentArray[$a1].".".$sFType;
$phpMach="./display_php.php?filename=".$sDir.$disp;
          //echo $sDir.'<br/>';
          //echo $disp.'<br/>';
          //echo $phpMach.'<br/>';
          $icon='<a href="./php/'.$disp.'"><img src="../fileIcon.jpg" /></a>';
          echo("<br/>".$icon." <a href=\"".$phpMach."\" TARGET=\"phpMain\">".$disp."</a>");     
          }
     }
?>

mysql_functions


<?php
/*
mysql_functions.php v1.0 ©2010 by Kristoffe Brodeur. All Rights Reserved.
02-09-2010 a series of functions to aid in mysql juggling
02-16-2010 added class flipNode with a usable key to identify each row
*/
//-----
function table_exists($table,$db=false)
     {
     //echo "table_exists~ $table $db<br />";
     //
     if(!$db)
          {
          $probe=mysql_query("SELECT DATABASE()");
          $db=mysql_result($probe,0);
          }
     $probe=mysql_query("
          SELECT COUNT(*) AS count
          FROM information_schema.tables
          WHERE table_schema='$db'
          AND table_name='$table'
          ");
     //echo mysql_result($probe,0)."<br />";
     return mysql_result($probe,0)==1;          
     }
//-----
function mysql_charSafe($str)
     {
     $old=Array("'",'"');
     $new=Array("\'",'\"');
     $output=str_replace($old,$new,$str);
     return $output;
     }
//-----
function clear_array($sArr)
     {
     $len=count($sArr);
     //
     for($a=0;$a<$len;$a++)
          {
          array_pop($sArr);
          }
     }
//-----you have to be logged in to your db before you use this, and query the table each row(A|B) with your key
Class mysql_flipNode
     {
     //
     function __construct($table,$rowA,$rowB,$key)
          {
          $this->table=$table;
          $this->key=$key;
          $this->rA=$rowA;
          $this->rB=$rowB;
          $this->rX=array();
          $this->cols=array();
          $this->find_cols();
          }
     //
     function find_cols()
          {
          //
          foreach($this->rA as $key=>$val)
               {
               $this->cols[]=$key;
               //$y=count($this->cols);
               $this->rX[$key]=$this->rA[$key];
               $this->rA[$key]=$this->rB[$key];
               $this->rB[$key]=$this->rX[$key];
               }
          //echo $this->strOut($this->rA,$this->rB)."<hr />";
          mysql_query($this->strOut($this->rA,$this->rB))or die(mysql_error());
          //echo $this->strOut($this->rB,$this->rA)."<hr />";
          mysql_query($this->strOut($this->rB,$this->rA))or die(mysql_error());
          }
     //
     function strOut($tgtA,$tgtB)
          {
          $len=count($this->cols);
          $str="UPDATE ".$this->table." SET ";
          //
          for($a=0;$a<$len-1;$a++)
               {
               $col=$this->cols[$a];
               //
               if($col!=$this->key)
                    {
                    $fixStr=mysql_charSafe($tgtA[$col]);//apostrophes in column strings can make it seem like an end single quote, '****'s' so '****\'s' is implemented for mysql and php in $**=mysql_charSafe($*)
                    $str.=$col."='".$fixStr."', ";
                    }
               }
          $col=$this->cols[$a];
          $str.=$col."='".$tgtA[$col]."' WHERE ".$this->key."='".$tgtB[$this->key]."'";
          return $str;
          }
     }
?>

mysql_saveRow


<?php
/*
mysql_updateRow.php v1.0 by Kristoffe Brodeur. ©2010 All Rights Reserved.
02-26-2010
send via $_POST from Flash
     table
     id
     cols (img,folder,blurb,blurb2) -> then each col POST variable sent will be read and formatted for the table insertion
*/
//get the cols first, then use it to find the $_POST vars second (vars1)
if(isset($_POST['cols']))
     {
     $cols=$_POST['cols'];
     }
$vars=explode(",",$cols);
$vars1="table,id,".$cols;
$varArr=explode(",",$vars1);
$len=count($varArr);
//
for($a=0;$a<$len;$a++)
     {
     //
     if(isset($_POST["{$varArr[$a]}"]))
          {
          ${$varArr[$a]}=$_POST["{$varArr[$a]}"];
          //echo $varArr[$a]."=".$_POST["{$varArr[$a]}"]."<br />";
          }
     }
$to_root="../";
require $to_root.'mS/admin/_info.php';
require $to_root.'mS/admin/settings.php';
require $to_root.'php/mysql_functions.php';
//

$len=count($vars);
$mysqlVars="";
$mysqlVals="";
$setStr="";
//
for($a=0;$a<$len-1;$a++)
     {
     $newStr=mysql_charSafe(${$vars[$a]});//variable with the name expressed in the asterisk area ${*}
     $mysqlVars.=$vars[$a].",";
     $mysqlVals.="'$newStr',";
     $setStr.=$vars[$a]."='$newStr',";
     }
$newStr=mysql_charSafe(${$vars[$a]});
$mysqlVars.=$vars[$a];
$mysqlVals.="'$newStr'";
$setStr.=$vars[$a]."='$newStr'";
//
$connect=mysql_connect($server,$user,$pass)or die("Error, login to $server failed. <span class='error'>".mysql_error()."</span>");
$link=mysql_connect($server,$user,$pass)or die('Error, login db failed');
$selDB=mysql_select_db($db,$link)or die("Could not select database $db: <span class='error'>".mysql_error()."</span>");
$query="UPDATE $table SET $setStr WHERE id='$id'";
//echo $query;
mysql_query($query,$link)or die("?success=".mysql_error());
mysql_close($connect);
echo "?success=true";
?>

parseTires2


<?php
//xml parser (c)2007 by kristoffe brodeur. all rights reserved
//03-27-2007
//----------
class tireGroup
     {
     var $tNodes;
     //----------
     function tireGroup()
          {
          $this->tNodes=Array();
          }
     }
//----------
class tireObj
     {
     var $M;
     var $N;
     var $P;
     //----------
     function tireObj($sentMeasure,$sentName,$sentPrice)
          {
          $this->M=$sentMeasure;
          $this->N=$sentName;
          $this->P=$sentPrice;
          }
     }
//----------
class XML_parseTires
     {
     var $tires=Array();//Array of tiredata
     var $tiPos;
     var $cssAddy;//address of css formatting file
     var $fName;//XML filename
     var $nName;//name of XML node
     var $tmpMake;
     var $tmpName;
     var $tmpPrice;
     var $tiGroup;//tire size array of objects
     var $tiGroupPos;//counter for tire size group
     //----------
     function XML_parseTires($filename,$sentCssAddy)
          {
          $this->tiPos=-1;
          $this->tiCol=-1;
          $this->tiGroupPos=-1;
          $this->tiGroup=Array();
          $this->fName=$filename;
          //
          if (!($this->xmlparser = xml_parser_create()))
               {
                die ("Cannot create parser");
               }
          //
          else
               {
               //echo ("XML parser created!<br/>");
               }     
          $this->cssAddy=$sentCssAddy;
          //only inside of a class is this needed
          xml_set_object($this->xmlparser,$this);
          xml_set_element_handler($this->xmlparser,"start_tag","end_tag");
          xml_set_character_data_handler($this->xmlparser,"tag_contents");
          $filename="./databases/wheels.xml";          
          //
          if(!($fp=fopen($this->fName,"r")))
               {     
               die("cannot open ".$this->fName);
               }
          //
          while($data=fread($fp,4096))
               {
               $data=eregi_replace(">"."[[:space:]]+"."<","><",$data);
               //
               if(!xml_parse($this->xmlparser,$data,feof($fp)))
                    {
                    $reason=xml_error_string(xml_get_error_code($this->xmlparser));
                    $reason.=xml_get_current_line_number($this->xmlparser);
                    die($reason);
                    }
               }
          //
          $this->init_html();
          $this->showBanner();
          $this->showLeft();
          $this->showTires();
          $this->end_html();     
          }
     //----------
     function showLeft()
          {
          echo'<div class="main">';
          echo'<p>Affordable Major Brand Tires in Stock!<br/>';
          echo'Most Commonly Ordered Tires Starting at:<br/><br/>';
          echo'<div class="imageBlock"><img src="tires.jpg" width="167" height="637" /></div>';
          echo'</p>';
          echo'</div>';
          }
     //----------
     function showBanner()
          {
          echo'<div class="header"><img src="../../backgrounds/wheelStrip.jpg" width="900" height="37" /></div>';
          echo'<div class="header"><img src="../../backgrounds/tires.jpg" width="900" height="64" /></div>';
          }
     //----------
     function showTires()
          {
          echo '<div class="middle">';
          //
          for($f1=0;$f1<4;$f1++)
               {
          $tgt=$this->tiGroup[$f1];
          $aa=count($this->tiGroup[$f1]->tNodes);
          echo'<span class="groups">* INCH</span><br/><table>';
          //
          for($g1=0;$g1<$aa;$g1++)
               {
               $b1=$this->tiGroup[$f1]->tNodes[$g1]->M;
               $b2=$this->tiGroup[$f1]->tNodes[$g1]->N;
               $b3=$this->tiGroup[$f1]->tNodes[$g1]->P;
               echo '<tr>';
               echo'<td>'.$b1." ".$b2.'</td><td>$'.$b3.'.00</td>';
               echo'</tr>';
               }
          echo'</table><br/>';
                    }
          echo'</div>';               
          }
     //----------
     function start_tag($parser,$name,$attribs)
          {
          $this->nName=$name;
          //
          switch ($name)
               {
               case "SIZE":
                    {
                    $this->tiGroupPos++;
                    $this->tiGroup[$this->tiGroupPos]=new tireGroup();
                    $this->tiPos=-1;//reset the array pointer to 0 to fill in from start in each group found
                    break;
                    }
               case "W":
                    {
                    $this->tiPos++;
                    break;
                    }
               default:
                    {
                    break;
                    }
               }
          //echo "[nName]".$name;
          }
     //----------
     function end_tag($parser,$name)
          {
          //echo "<-".$name."<br/>";
          }
     //----------
     function tag_contents($parser,$data)
          {
          //
          switch ($this->nName)
               {
               case "M":
                    {
                    $this->tmpMake=$data;
                    break;
                    }
               case "N":
                    {
                    $this->tmpName=$data;
                    break;
                    }
               case "P":
                    {
                    $this->tmpPrice=$data;
                    $this->tiGroup[$this->tiGroupPos]->tNodes[$this->tiPos]=new tireObj($this->tmpMake,$this->tmpName,$this->tmpPrice);
                    break;
                    }
               }
          }
     //----------
     function init_html()
          {
          echo '<html>';
          echo '<head>';
          echo '<title>Rims for Sale</title>';
          echo '<link href="'.$this->cssAddy.'" rel="stylesheet" type="text/css" />';
          echo '<body>';
          echo '<div class="wrap">';
          }
     //----------
     function end_html()
          {
          echo '</div>';
          echo '</body>';
          echo '</html>';
          }
     }
//----------
$filename="../../databases/tires.xml";
$cssAddy="../../tires.css";
$test1=new XML_parseTires($filename,$cssAddy);
?>

parseXML


<?php
//04-07-2008 COMPACT VERSION v1.0
//08-24-2008 added CSS formatting and colored DIV alternations
//08-28-2008 found a way to replace &->## and then ##->& so the PHP parser wouldn't freak out for HTML links with variables
//02-23-2009 added php5 __construct class modifications
//generic xml parser to associate arrays
//©2008 All Rights Reserved by Kristoffe Brodeur
Class XML_parse
{
var $fName;
var $depth;
var $nest;
var $nodes;
var $XML;
var $tgt;
function __construct($sFName)
{
$this->nest=array();
$this->depth=-1;
$this->fName=$sFName;
$this->XML=new NodeArray();
if(!($this->xmlparser=xml_parser_create())){die("Cannot create parser.");}
else
{
//echo "Xml parser created!<br />";
}
xml_set_object($this->xmlparser,$this);
xml_set_element_handler($this->xmlparser,"start_tag","end_tag");
xml_set_character_data_handler($this->xmlparser,"tag_contents");
if(!($fp=fopen($this->fName,"r"))){die("cannot open ".$this->fname);}
while($data=fread($fp,4096))
{
$data=eregi_replace(">"."[[:space:]]+"."<","><",$data);
$data=eregi_replace("&","##",$data);
if(!xml_parse($this->xmlparser,$data,feof($fp)))
{
$reason=xml_error_string(xml_get_error_code($this->xmlparser));
$reason.=xml_get_current_line_number($this->xmlparser);
die($reason);
}
}
}
function addCurrData($sData)
{
$pNode=$this->XML;
$cnt=count($this->nest);
for($a1=0;$a1<$cnt;$a1++)
{
$ptr=$this->nest[$a1];
$pNodeCnt=count($pNode->{$ptr});
$pNode=$pNode->{$ptr}[$pNodeCnt-1];
}
$pNode->DATA=$sData;
}
function createNode($sNode)
{
$pNode=$this->XML;
if($this->depth==0){}
else
{
$cnt=count($this->nest);
for($a1=0;$a1<$cnt-1;$a1++)
{
$ptr=$this->nest[$a1];
$pNodeCnt=count($pNode->{$ptr});
$pNode=$pNode->{$ptr}[$pNodeCnt-1];
}
}
AddNode($pNode,$sNode);
$pCnt=count($pNode->{$sNode});
}
function start_tag($parser,$name,$attribs)
{
$lNode=strtolower($name);
$this->depth++;
array_push($this->nest,$lNode);
$this->createNode($lNode);
$cnt=count($attribs);
$tab=$this->tabit($this->depth);
}
function end_tag($parser,$name)
{
$tab=$this->tabit($this->depth);
$lNode=strtolower($name);
$this->depth--;
array_pop($this->nest);
}
function tag_contents($parser,$data)
{
$data=eregi_replace("##","&",$data);
$this->addCurrData($data);
//echo '<br />['.$data.']';
}
function showNest()
{
$nL=count($this->nest);
for($a1=0;$a1<$nL;$a1++){echo "[".$this->nest[$a1]."]";}
}
function tabit($amt)
{
$str="";
$chr="   ";
for($a1=0;$a1<$amt;$a1++){$str.=$chr;}
return $str;
}
}
Class Node
{
var $ID;
var $DATA;
function __construct($sID,$sText)
{
$this->ID=$sID;
if($sText!=""){$this->DATA=$sText;}
else{$this->DATA="-";}
}
}
function AddNode($tgtPar,$sName,$sText)
{
if(!$tgtPar->{$sName}){$tgtPar->{$sName}=array();}
$ptr=count($tgtPar->{$sName});
$tgtPar->{$sName}[$ptr]=new Node($sName,$sText);
}
Class NodeArray
{
function __construct($sRootNode){}
}
?>

path


<?php
//webroot v1.0
//©2009 by Kristoffe Brodeur. All Rights Reserved.
//find website root and display and / or send back to flash
$httpRoot=$_SERVER['HTTP_HOST'];
$uri=$_SERVER['REQUEST_URI'];
$base=basename($uri);
$baseLen=strlen($base);
$basePath=substr($uri,0,-$baseLen);
$path="http://".$httpRoot.$basePath;
echo $path;
?>

sendMail


<?php
$body="";     //body of the email to send
//
$OS=strtoupper(substr(PHP_OS,0,3)=='WIN');
//
switch($OS)
{
case "WIN":
$eol="\r\n";
break;
case "MAC":
$eol="\r";
break;
default:
$eol="\n";
break;
}
//
foreach($_POST as $varname=>$varvalue)
     {
     $body.="<b>$varname</b><br />$varvalue<br />";
     }
//echo $body;
//
$mailto="jmarmon@comcast.net";
//mailto="kristoffe.brodeur@verizon.net";
$mailsubj="I want to join the team";
//
//$eMail is a variable in the html FORM named eMail
//
$mailhead="From: ".$eMail.$eol;
$mailhead.="X-Mailer: PHP v".phpversion().$eol;
$mailhead.="MIME-Version: 1.0".$eol;
$mailhead.="Content-Type: text/html; charset=iso-8859-1".$eol;
$mailhead.="Content-Transfer-Encoding: 8bit".$eol.$eol;
//
//echo '<br/>'.$mailhead;
$sent=mail($mailto,$mailsubj,$body,$mailhead);
//
if($sent)
{
echo "mail successful";
}
else
{
echo "doesn't work";
}
//phpinfo();
?>

XML_parse


<?php
//04-07-2008 COMPACT VERSION v1.0
//08-24-2008 added CSS formatting and colored DIV alternations
//08-28-2008 found a way to replace &->## and then ##->& so the PHP parser wouldn't freak out for HTML links with variables
//02-16-2009 made XML_parse.php it's own file to be included in other php files by include 'XML_parse.php';
//02-23-2009 added __contruct php5 class model changes
//07-01-2009 made all calls have proper amounts of arguments
//07-14-1009 found that if(!tgtPar->{$sName}) throws an error but if(!isset(tgtPar->{$sName}) does not, thus the apache error.log fills up slower!
//generic xml parser to associate arrays
//©2008,9 by Kristoffe Brodeur. All Rights Reserved.
Class Node
{
var $ID;
var $DATA;
function __construct($sID,$sText)
{
$this->ID=$sID;
if($sText!=""){$this->DATA=$sText;}
else{$this->DATA="-";}
}
}
Class NodeArray
{
function __construct(){}
}
function AddNode($tgtPar,$sName,$sText)
{
//
if(!isset($tgtPar->{$sName}))
     {
     $tgtPar->{$sName}=Array();
     }
$ptr=count($tgtPar->{$sName});
$tgtPar->{$sName}[$ptr]=new Node($sName,$sText);
}
Class XML_parse
{
var $fName;
var $depth;
var $nest;
var $nodes;
var $XML;
var $tgt;
function __construct($sFName)
{
$this->nest=array();
$this->depth=-1;
$this->fName=$sFName;
$this->XML=new NodeArray(null);
if(!($this->xmlparser=xml_parser_create())){die("Cannot create parser.");}
else
{
//echo "Xml parser created!<br />";
}
xml_set_object($this->xmlparser,$this);
xml_set_element_handler($this->xmlparser,"start_tag","end_tag");
xml_set_character_data_handler($this->xmlparser,"tag_contents");
if(!($fp=fopen($this->fName,"r"))){die("cannot open ".$this->fname);}
while($data=fread($fp,4096))
{
$data=eregi_replace(">"."[[:space:]]+"."<","><",$data);
$data=eregi_replace("&","##",$data);
if(!xml_parse($this->xmlparser,$data,feof($fp)))
{
$reason=xml_error_string(xml_get_error_code($this->xmlparser));
$reason.=xml_get_current_line_number($this->xmlparser);
die($reason);
}
}
}
function addCurrData($sData)
{
$pNode=$this->XML;
$cnt=count($this->nest);
for($a1=0;$a1<$cnt;$a1++)
{
$ptr=$this->nest[$a1];
$pNodeCnt=count($pNode->{$ptr});
$pNode=$pNode->{$ptr}[$pNodeCnt-1];
}
$pNode->DATA=$sData;
}
function createNode($sNode)
{
$pNode=$this->XML;
if($this->depth==0){}
else
{
$cnt=count($this->nest);
for($a1=0;$a1<$cnt-1;$a1++)
{
$ptr=$this->nest[$a1];
$pNodeCnt=count($pNode->{$ptr});
$pNode=$pNode->{$ptr}[$pNodeCnt-1];
}
}
AddNode($pNode,$sNode,null);
$pCnt=count($pNode->{$sNode});
}
function start_tag($parser,$name,$attribs)
{
$lNode=strtolower($name);
$this->depth++;
array_push($this->nest,$lNode);
$this->createNode($lNode);
$cnt=count($attribs);
$tab=$this->tabit($this->depth);
}
function end_tag($parser,$name)
{
$tab=$this->tabit($this->depth);
$lNode=strtolower($name);
$this->depth--;
array_pop($this->nest);
}
function tag_contents($parser,$data)
{
$data=eregi_replace("##","&",$data);
$this->addCurrData($data);
//echo '<br />['.$data.']';
}
function showNest()
{
$nL=count($this->nest);
for($a1=0;$a1<$nL;$a1++){echo "[".$this->nest[$a1]."]";}
}
function tabit($amt)
{
$str="";
$chr="   ";
for($a1=0;$a1<$amt;$a1++){$str.=$chr;}
return $str;
}
}
?>

XML_parseSave3


<?php
/*
12-21-2009
XML_parseSave3.php v3 by Kristoffe Brodeur. ©2009 All Rights Reserved.
*/
//-----
Class Spitter
     {
     var $stack;
     var $xml_code;
     var $folder;
     var $newFile;
     //
     function __construct($sBase,$sFolder,$sNewFile)
          {
          $this->stack=Array();
          $this->looper($sBase);
          $this->folder=$sFolder;
          $this->newFile=$sNewFile;
          $this->save_XML();
          }
     function save_XML()
          {
          $nF=$this->folder.$this->newFile;
          $f=fopen($nF,"w");
          fwrite($f,$this->xml_code);
          fclose($f);
          echo "file saved. [$nF]";
          }
     //
     function looper($cTgt)
          {
          //
          $nType=gettype($cTgt);
          //
          switch($nType)
               {
               //
               case "object":
                    //echo "[O]";
                    $attrChk=0;
                    $arrCnt=0;
                    //
                    foreach($cTgt as $key=>$val)
                         {
                         $cType=gettype($val);
                         //
                         switch($cType)
                              {
                              //
                              case "array":
                                   {
                                   $arrCnt++;
                                   $this->stack[]=$key;
                                   //
                                   $cLen=count($this->stack);
                                   //
                                   if($cLen>1&&$arrCnt<2)
                                        {
                                        $this->xml_code.=">";
                                        }
                                   $this->looper($cTgt->$key);
                                   break;
                                   }
                              case "string":
                                   {
                                   $sLen=count($this->stack);
                                   $cNode=$this->stack[$sLen-1];
                                   //
                                   if($val!=$cNode)
                                        {
                                        //
                                        if($val!="-")
                                             {
                                             $val=preg_replace('/&(?!amp;)/','&',$val);//ready for web parsing & becomes & only if & doesn't already have amp; after it
                                             //
                                             $kStr=substr($key,0,2);
                                             //
                                             if($kStr!="__")
                                                  {
                                                  $this->xml_code.=$val;
                                                  }
                                             else
                                                  {
                                                  $attrChk=1;
                                                  $keyFix=substr($key,2);
                                                  $this->xml_code.=' '.$keyFix.'="'.$val.'"';
                                                  }
                                             }
                                        }
                                   break;
                                   }
                              }
                         }
                    $cLen=count($this->stack);
                    //
                    if($attrChk==1&&$cLen>2)
                         {
                         $this->xml_code.=">";
                         }
                    break;
               //
               case "array":
                    //
                    $len=count($cTgt);
                    $sLen=count($this->stack);
                    //
                    for($a=0;$a<$len;$a++)
                         {
                         $this->xml_code.="<".$this->stack[$sLen-1];
                         $attrs=false;
                         //
                         foreach($cTgt[$a] as $key=>$val)
                              {
                              //
                              $cType=gettype($val);
                              //
                              switch($cType)
                                   {
                                   case "string":
                                        $kStr=substr($key,0,2);
                                        //
                                        if($kStr=="__")
                                             {
                                             $attrs=true;
                                             }
                                        break;
                                   default:
                                        break;
                                   }
                              }
                         //
                         if($attrs==false&&$sLen>2)
                              {
                              $this->xml_code.=">";
                              }
                         //
                         $this->looper($cTgt[$a]);
                         $this->xml_code.="</".$this->stack[$sLen-1].">";
                         }
                    array_pop($this->stack);
                    break;
               }
          }
     }
//-----
echo "spitter 3 test<hr />";
require "XML_parsev2.php";
$file="db/attrs_test1.xml";
$file="db/videos_youtube.xml";
//$file="db/sections_gallery.xml";
$test=new XML_parse($file);
$folder="db/";
$newfile="test.xml";
$spit1=new Spitter($test->XML,$folder,$newfile);
?>

xml_parseTest


<?php
//xml parser (c)2007 by kristoffe brodeur. all rights reserved
//03-26-2007
$wheels=Array();
$whPos=-1;
class wheelObj
     {
     var $ID;
     var $FINISH;
     var $SIZES;
     //----------
     function wheelObj($sentID,$sentFinish,$sentSizes)
          {
          $this->ID=$sentID;
          $this->FINISH=$sentFinish;
          $this->SIZES=$sentSizes;
          }
     }
//
class XML_parseWheels
     {
     var $wheels=Array();
     var $whPos;
     var $xmlparser;
     var $tmpName;
     var $tmpID;
     var $tmpFinish;
     var $tmpSizes;
     var $nName;
     var $rFolder;
     var $cssAddy;
     var $whCol;
     var $whLim;
     var $fName;
     //----------
     function XML_parseWheels($filename,$folder,$sentCssAddy)
          {
          $this->whPos=-1;
          $this->whCol=-1;
          $this->whLim=3;
          $this->fName=$filename;
          //
          if (!($this->xmlparser = xml_parser_create()))
               {
                die ("Cannot create parser");
               }
          //
          else
               {
               //echo ("XML parser created!<br/>");
               }
          $this->rFolder=$folder;
          $this->cssAddy=$sentCssAddy;
          //only inside of a class is this needed
          xml_set_object($this->xmlparser,$this);
          xml_set_element_handler($this->xmlparser,"start_tag","end_tag");
          xml_set_character_data_handler($this->xmlparser,"tag_contents");
          $filename="./databases/wheels.xml";
          //
          if(!($fp=fopen($this->fName,"r")))
               {     
               die("cannot open ".$this->fName);
               }
          //
          while($data=fread($fp,4096))
               {
               $data=eregi_replace(">"."[[:space:]]+"."<","><",$data);
               //
               if(!xml_parse($this->xmlparser,$data,feof($fp)))
                    {
                    $reason=xml_error_string(xml_get_error_code($this->xmlparser));
                    $reason.=xml_get_current_line_number($this->xmlparser);
                    die($reason);
                    }
               }
          //
          $this->init_html();
          $this->note();
          $this->showWheels();
          $this->plugAd();
          $this->end_html();
          //
          }
     //----------
     function end_html()
          {
          echo '</div>';
          echo '</body>';
          echo '</html>';
          }
     //----------
     function init_html()
          {
          echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">';
          echo '<html>';
          echo '<head>';
          echo '<meta http-equiv="Content-Type" content="text/html;charset=utf-8" >';
          echo '<title>Rims for Sale</title>';
          echo '<link href="'.$this->cssAddy.'" rel="stylesheet" type="text/css" />';
          echo '<body>';
          echo '<div class="wrap">';
          echo '<div class="header"><img src="../../backgrounds/wheelStrip.jpg" /></div>';
          echo '<div class="header"><img src="../../backgrounds/rims.jpg"/></div>';
          }
     //----------
     function note()
          {
          echo '<div class="main">';
          echo 'lalalalalalalallala';
          echo '</div>';
          }
     //----------
     function plugAd()
          {
          $adAddy="../../ads/rimAd.jpg";
          echo '<div class="topAd"><img src="'.$adAddy.'"/></div><br/>';
          }
     //----------
     function showWheels()
          {
          echo '<div class="wheels">';
          echo '<table width=700 border="0">';
          echo '<tr>';
          for($a1=0;$a1<count($this->wheels);$a1++)
               {
               $this->whCol++;
               //
               if($this->whCol==$this->whLim)
                    {
                    echo'</td>';
                    echo'<tr>';
                    $this->whCol=0;
                    //echo "<br/>";
                    }
               echo'<td>';
               $txt1=$this->wheels[$a1]->ID;
               $txt2=$this->wheels[$a1]->FINISH;
               $txt3=$this->wheels[$a1]->SIZES;
               $sizes=explode(",",$txt3);
               //$img="<img src=/"".$this->rFolder.$txt1.".jpg/">";
               //echo '<div class="wheelArea">';
               echo '<table width=100% border="0">';
               echo '<tr valign="top">';
               echo '<td>';
               echo '<img src="'.$this->rFolder.$txt1.'.jpg"/>';
               echo '</td>';
               echo '<td>';
               echo '<table width=100% border="0">';
               echo '<tr><td><span class="ti">'.$txt1.'</span>/'.$txt2.'</td></tr>';
               //echo '<tr><td>'.$txt2.'</td></tr>';
               //
               for($b1=0;$b1<count($sizes);$b1++)
                    {
                    echo '<tr><td>'.$sizes[$b1].'</td></tr>';
                    }
               echo '</table>';
               echo '</td>';
               echo '</tr>';
               //echo '</div>';
               echo '</table>';
               }
          echo '</tr>';
          echo '</table>';
          echo '</div>';
          }          
     //----------
     function start_tag($parser,$name,$attribs)
          {
          $this->nName=$name;
          //
          switch ($name)
               {
               case "WH":
                    {
                    $this->whPos++;
                    break;
                    }
               default:
                    {
                    break;
                    }
               }
          //echo "[nName]".$name;
          }
     //----------
     function end_tag($parser,$name)
          {
          //echo "<-".$name."<br/>";
          }
     //----------
     function tag_contents($parser,$data)
          {
          //
          switch ($this->nName)
               {
               case "ID":
                    {
                    $this->tmpID=$data;
                    break;
                    }
               case "F":
                    {
                    $this->tmpFinish=$data;
                    break;
                    }
               case "S":
                    {
                    $this->tmpSizes=$data;
                    //echo "[".$this->whPos."]<br/>";
                    //echo "[ID]".$this->tmpID."<br/>";                    
                    //echo "[FINISH]".$this->tmpFinish."<br/>";
                    //echo "[SIZES]".$this->tmpSizes."<br/><br/>";
                    $this->wheels[$this->whPos]=new wheelObj($this->tmpID,$this->tmpFinish,$this->tmpSizes);
                    break;
                    }
               }
          }
     }
//----------
//echo "Ready to begin the XML class parser!</br>";
$filename="../../databases/wheels.xml";
$folder="../../pics/rims/";
$cssAddy="../../sale.css";
$test1=new XML_parseWheels($filename,$folder,$cssAddy);
?>

XML_parsev2


<?php
/*
generic xml parser to associate arrays
©2008,9 by Kristoffe Brodeur. All Rights Reserved.

04-07-2008     COMPACT VERSION v1.0
08-24-2008     added CSS formatting and colored DIV alternations
08-28-2008     found a way to replace &->## and then ##->& so the PHP parser wouldn't freak out for HTML links with variables
02-16-2009     made XML_parse.php it's own file to be included in other php files by include 'XML_parse.php';
02-23-2009     added __contruct php5 class model changes
07-01-2009     made all calls have proper amounts of arguments
07-14-1009     found that if(!tgtPar->{$sName}) throws an error but if(!isset(tgtPar->{$sName}) does not, thus the apache error.log fills up slower!
12-09-2009     added v2, made attributes load as object properties without an array structure
               made a temp file time().ip.xml of the user visiting using the engine to properly encode all xml files then delete when complete
*/
//-----
Class Node
{
var $ID;
var $DATA;
function __construct($sID,$sText)
{
$this->ID=$sID;
if($sText!=""){$this->DATA=$sText;}
else{$this->DATA="-";}
}
}
Class NodeArray
{
function __construct(){}
}
function AddNode($tgtPar,$sName,$sText)
{
//
if(!isset($tgtPar->{$sName}))
     {
     $tgtPar->{$sName}=Array();
     }
$ptr=count($tgtPar->{$sName});
$tgtPar->{$sName}[$ptr]=new Node($sName,$sText);
}
Class XML_parse
     {
     var $fName;
     var $depth;
     var $nest;
     var $nodes;
     var $XML;
     var $tgt;
     var $tempFile;
     //
     function __construct($sFName)
          {
          $this->nest=array();
          $this->depth=-1;
          $this->fName=$sFName;
          $this->XML=new NodeArray(null);
          //-----
          $this->checkParse();
          //-----
          //
          if(!($this->xmlparser=xml_parser_create())){die("Cannot create parser.");}
          else
               {     
               //echo "Xml parser created!<br />";
               }
          xml_set_object($this->xmlparser,$this);
          xml_set_element_handler($this->xmlparser,"start_tag","end_tag");
          xml_set_character_data_handler($this->xmlparser,"tag_contents");
          //
          if(!($fp=fopen($this->tempFile,"r"))){die("cannot open ".$this->tempFile);}
          //
          while($data=fread($fp,4096))
               {
               $data=eregi_replace(">"."[[:space:]]+"."<","><",$data);
               $data=eregi_replace("&","##",$data);
               //
               if(!xml_parse($this->xmlparser,$data,feof($fp)))
                    {
                    $reason=xml_error_string(xml_get_error_code($this->xmlparser));
                    $reason.=xml_get_current_line_number($this->xmlparser);
                    die($reason);
                    }
               }
          fclose($fp);
          chmod($this->tempFile,0644);
          unlink($this->tempFile);//delete converted xml temp file
          }
     //
     function checkParse()
          {
          $oldXML="";
          $handle=@fopen($this->fName,"r");
          //
          while(!feof($handle))
               {
               $oldXML.=fgets($handle,4096);
               }          
          fclose($handle);
          $oldXML=preg_replace('/&(?!amp;)/','&',$oldXML);
          $timeSignature=time();
          $ip=preg_replace('/\./','',$_SERVER['REMOTE_ADDR']);// escape metacharaters like dot . with a backslash \ -> \.
          $this->tempFile=$ip.time().".xml";
          $f=fopen($this->tempFile,"w");
          fwrite($f,$oldXML);
          fclose($f);
          }
     //
     function addCurrData($sData)
{
$pNode=$this->XML;
$cnt=count($this->nest);
for($a1=0;$a1<$cnt;$a1++)
{
$ptr=$this->nest[$a1];
$pNodeCnt=count($pNode->{$ptr});
$pNode=$pNode->{$ptr}[$pNodeCnt-1];
}
$pNode->DATA=$sData;
}
//
     function createNode($sNode,$attribs)
{
$pNode=$this->XML;
if($this->depth==0){}
else
{
$cnt=count($this->nest);
for($a1=0;$a1<$cnt-1;$a1++)
{
$ptr=$this->nest[$a1];
$pNodeCnt=count($pNode->{$ptr});
$pNode=$pNode->{$ptr}[$pNodeCnt-1];
}
}
AddNode($pNode,$sNode,null);
          $len=count($pNode->{$sNode});
          //echo "$sNode:$len<br />";
          //
          if(is_array($attribs))
               {
               //
               while(list($key,$val)=each($attribs))
                    {
                    $key="__".strtolower($key);
                    $val=str_replace('##amp;','&',$val);//php parser replaces & with ##, so when read in from & to & fore readability, then changed to ##amp;, search and convert ##amp; to &
                    $pNode->{$sNode}[$len-1]->{$key}=$val;
                    //echo "|____[$key] ".$pNode->{$sNode}[$len-1]->{$key}."<br />";
                    }
               }
          //
          $pCnt=count($pNode->{$sNode});
}
//
     function start_tag($parser,$name,$attribs)
{
$lNode=strtolower($name);
$this->depth++;
array_push($this->nest,$lNode);
$this->createNode($lNode,$attribs);
$tab=$this->tabit($this->depth);
}
//
     function end_tag($parser,$name)
{
$tab=$this->tabit($this->depth);
$lNode=strtolower($name);
$this->depth--;
array_pop($this->nest);
}
//
     function tag_contents($parser,$data)
{
$data=eregi_replace("##","&",$data);
$this->addCurrData($data);
//echo '<br />['.$data.']';
}
//
     function showNest()
{
$nL=count($this->nest);
for($a1=0;$a1<$nL;$a1++){echo "[".$this->nest[$a1]."]";}
}
//
     function tabit($amt)
{
$str="";
$chr="   ";
for($a1=0;$a1<$amt;$a1++){$str.=$chr;}
return $str;
}
     }
?>