Hey, after some thinking I remembered that you can use strings as arrays and use like $string[0] will give you whatever the first character is in the string. I used that idea and used 0 regular expressions in this thing. I am sure I could have but shows that you can do things in PHP so many different ways. :-D. My signature is so valid here! LOL.
<?php
// This will count the entries we have.
$entries = 1;
// Define the filename to the SINGLE LINE TELEPHONES.
$stl_filename = "C:\\www\\EMML-SLT.FIL";
// Open the file with READ permissions.
$stl_handle = fopen($stl_filename, "r");
// Read the contents into this string.
$contents_stl = fread($stl_handle, filesize($stl_filename));
// Define the filename
$mdlt_filename = "C:\\www\\EMML-MDLT.FIL";
// Open the filename with READ permissions
$mdlt_handle = fopen($mdlt_filename, "r");
// Reads the contents into $contents_mdlt.
$contents_mdlt = fread($mdlt_handle, filesize($mdlt_filename));
// Takes both streams and makes them into one string!
$contents = $contents_stl . $contents_mdlt;
// takes off the whitespace at the beginning and end.
$contents = trim($contents);
// This takes all spaces out of the system!
$contents = str_replace(" ","",$contents);
// This looks for the line that says PairedDN and makes it Paired__.
$contents = str_replace("dDN=","d__=",$contents);
// This looks for the part that says pType and makes it p_ype.
$contents = str_replace("pType","p_ype",$contents);
// This will look for DN= and make it ;DN=
$contents = str_replace("DN=",";DN=",$contents);
// All the prior commands are used to make an array.
// This command will split the contents into an array making it easier
// to search. It finds a new key at each ;
$contents_array = explode(";",$contents);
// This will take out the first line which is the commands used to derive the dump.
unset($contents_array[0]);
// This takes the array and each key becomes a string.
foreach($contents_array as $temp_contents)
{
// Sets the variables back to blanks. That way duplication
// doesn't happen.
$build_dn = "";
$build_en = "";
$build_name = "";
$build_type = "";
// This will look to to find DN=
if(($temp_contents[0] == "D") && ($temp_contents[1] == "N") && ($temp_contents[2] == "="))
{
// Uses a FOR statement to build the 4 numbers following DN=
for($dn_count = 3; $dn_count < 7; $dn_count++)
{
$build_dn = $build_dn . "$temp_contents[$dn_count]";
}
// Uses a FOR statement to build the 8 numbers following the EN=
for($en_count = 10; $en_count < 18; $en_count++)
{
$build_en = $build_en . "$temp_contents[$en_count]";
}
// Finds the Name= part.
if(($temp_contents[18] == "N") && ($temp_contents[19] == "a") && ($temp_contents[20] == "m") && ($temp_contents[21] == "e") && ($temp_contents[22] == "="))
{
// Checks to see if there is a ' to start a name. If not then it says No Name
if($temp_contents[23] == "'")
{
// Internal Name counter.
$name_count = 24;
// This will go until it gets to the second '.
while($temp_contents[$name_count] != "'")
{
// Builds the name string.
$build_name = $build_name . "$temp_contents[$name_count]";
$name_count++;
}
}else{
$build_name = "<b>No Name</b>";
}
}
// This will find the Type=
$type_counter = 1;
// Gets the length of the string it has been taking apart.
$final_count = strlen($temp_contents);
// Uses a FOR statement to search the entire string again.
for($type_counter; $type_counter < $final_count; $type_counter++)
{
// Looks for Type=
// I couldn't just give a exact place with the others because there are too many variables
// that can be played into this thing. Such as long names and others.
if(($temp_contents[$type_counter] == "T") && ($temp_contents[$type_counter+1] == "y") && ($temp_contents[$type_counter+2] == "p") && ($temp_contents[$type_counter+3] == "e") && ($temp_contents[$type_counter+4] == "="))
{
// This will see if the name is actually defined.
// If not then it says No Type Defined!
if($temp_contents[$type_counter+5] == "P")
{
$build_type = "No Type Defined!";
}else{
// Uses a FOR statement to get the next 5 characters.
for($i = $type_counter+5; $i < $type_counter+10; $i++)
{
// Builds the type.
$build_type = $build_type . "$temp_contents[$i]";
}
}
}
}
// Prints the DN, EN, Name, and Type.
echo "DN=$build_dn, ";
echo "EN=$build_en, ";
echo "Name=$build_name, ";
echo "Type=$build_type<br><br>";
$entries++;
}
}
// Prints the number of entries we have.
echo "<br><br>Entries: $entries";
fclose($stl_handle);
fclose($mdlt_handle);
?>
There it is for ya'll. If you have anything coming from a PBX and need to use the data derived from it then this code will take that out for you. Here is how you get data out from the PBX.
This folder was created to house extracts from the EMML
system. Standard extracts used by Infrastructure as of
April 21, 2004 are:
DIS PICG
DIS MLDT
DIS SLT
These should be captured to the appropriate files named
EMML-PICKUP.FIL
EMML-MDLT.FIL
EMML-SLT.FIL
respectively. The data is then extracted using SAS and
accessible using Cognos.
There ya'll go! Take it easy, glad I got this deadline done.
Chad