Sorry, I didn't as for you to create a plug and play situation. I just wanted to know where in my script I needed to put it and how my variables would fit into your code. If that sounded like I wanted you to write my code, I apologize, that is not what I wanted.
I am going to include a copy of both files I am using for this. I sanitized them of any info that we don't want the whole world seeing. Just something about me, I write myself little notes in the script to explain what I am doing where I am doing it, so you will see a lot of //..... After I get the script done, I tidy it up so it isn't so long.
I had to upload the .xml file as a .txt file because of the rules of the forum, but it could easily be changed back to a .xml file when downloaded. It is saved on my computer as a .xml.
So if you could look at them and let me know if I have your code in the correct spot.
Thanks
phxml.php
<?php
$rowcounter = 99;
$connectionstring = odbc_connect("database", "username", "password");
//Query database for Names and numbers
$Query = "select pyemp#, pyfnam, pysnam
from IESFILE.PYMAST
where pystat = 'A'
order by pyemp#";
$queryexe = odbc_do($connectionstring, $Query);
while(odbc_fetch_row($queryexe))
{
$pyemp = trim(odbc_result($queryexe, 1));
$pyfnam = trim(odbc_result($queryexe, 2));
$pysnam = trim(odbc_result($queryexe, 3));
$Query1 = "select drmisc
from IESFILE.DRIVERS
where drcode = '$pyemp'";
$queryexe1 = odbc_do($connectionstring, $Query1);
while(odbc_fetch_row($queryexe1))
{
$drmisc = trim(odbc_result($queryexe1,1));
$misc = preg_replace("/[^0-9]/","",$drmisc);
//put in 'if' statement saying 'if $misc starts with 402 or 712, do nothing, if anything else, add a '1' except if it already starts with a '1'
if (preg_match('/^1/', $misc)){
}elseif (preg_match('/^402/', $misc)){
}elseif (preg_match('/^712/', $misc)){
}else{
$misc = "1".$misc;
}
}
$rowcounter = $rowcounter + 1;
$rc = $rowcounter + 200;
$fullname = $pyfnam." ".$pysnam;
//File to be seached and edited...
$fileurl = 'data2.xml';
//Search file for this line of code...
//$search = "<item row=\"".$rowcounter."\">\n\t<c0>".$rowcounter."</c0>\n<c1>*".$rc."</c1>\n<c2 />\n<c3 />"; //Long version...Too Much Info
//$search = $rc."</c1>"; //This one works, but doesn't get rid of the <c2 /> or <c3 />
$search = $rc."</c1> \n <c2 /> \n <c3 />";
//Create Data line to be entered into file...
//$data = "<item row=\"".$rowcounter."\">\n\t<c0>".$rowcounter."</c0>\n\t<c1>*".$rc."</c1>\n\t<c2>9".$misc."</c2>\n\t<c3>".$fullname."</c3>"; //too much info
$data = $rc."</c1> \n <c2>9".$misc."</c2> \n <c3>".$fullname."</c3> ";
//This opens file and searches the file and changes the searched info to the data created...
$file_contents = file_get_contents($fileurl);
$fh = fopen($fileurl, "w");
$file_contents = str_replace($search,$data,$file_contents);
fwrite($fh, $file_contents);
//added xyph code
$data2 = array( 'name' => $fullname, 'number' => $misc );
//$xml is data2.xml
$xml = <<<HEREDOC
$file_contents
HEREDOC;
foreach( $data2 as $key => $row ) {
if( ($pos = strpos( $xml, '<item row="'.$row.'">' )) === FALSE )
continue;
$c2 = strpos( $xml, '<c2 />', $pos );
$c3 = strpos( $xml, '<c3 />', $pos );
$xml = substr( $xml, 0, $c2 ) . '<c2>'.$row['number'].'</c2>' .substr( $xml, $c2 + 6, $c3 - $c2 - 6 ) . '<c3>'.$row['name'].'</c3>' . substr( $xml, $c3 + 6 );
}
unset($misc); //unset variable so it doesn't use the previous employee's number again...
$misc = " no number"; // Any number will do here, ***will have to go into the database and add everyone phone number.
fclose($fh);
}
echo '<pre>' . htmlspecialchars( $xml ) . '</pre>';
odbc_close($connectionstring);
echo "done!";
//Things that need to happen to make this work.
//Run when anyone is hired or fired/quits
//Number for the person is put in the Driver Master's Misc Line, if local, just 402, if long distance in NE with 402, add the 1.
//if driver's # is local, just put in 402 EXAMPLE Omaha 402-733-2200 DONE!
//if driver's # is long distance in the 402 area code, add "1" EXAMPLE Lincoln 1-402-733-2200 DONE!
//This applies to 712 also DONE!
//if driver lives anywhere else, no need to add the '1', program will add it for you. DONE!
//take info and place it into xml file
//make if statement to update file after xml is already used and needs to be updated
?>
[attachment deleted by admin]