The application has to do with an alarm system. When an alarm event occurs it generates a text file that has a 16 digit/character number at the bottom of the text file and logs it on my linux server. I am trying to translate the code into english using str_replace.
The problem i have in the first example below is the last character/number is a checksum and changes so my search never comes up with a match. I got around this by just seaching the first 15 digits/characters even though the string is 16 digits/characters. This works and i have a valid match. Problem is once the replace happens, the 16th digit/character is showing up to the right of the replace.
The problem i have in the second example below is only the first 10 digits are constant and the remaining 6 are never the same.
Question /Example 1: I can only search on the first 15 characters/digits of the 16 generated by the alarm as the 16th is never the same.
The alarm generates the following text file:
[metadata]
PROTOCOL=ADEMCO_CONTACT_ID
CALLINGFROM=5085551212
CALLERNAME=
TIMESTAMP=Wed Nov 21, 2012 @ 13:33:58 EST
[events]
769418130101000B
I execute the following php script:
[php]
<?php $file = '/etc/asterisk/alarm/latest.txt'; // // System Alarms file_put_contents($file,str_replace('7694181110','7694181110 Fire Alarm ',file_get_contents($file))); file_put_contents($file,str_replace('7694183110','7694183110 Fire Alarm Clear ',file_get_contents($file))); file_put_contents($file,str_replace('7694181111','7694181111 Smoke Alarm ',file_get_contents($file))); file_put_contents($file,str_replace('7694183111','7694183111 Smoke Alarm Clear ',file_get_contents($file))); file_put_contents($file,str_replace('7694181302','7694181302 Low System Battery ',file_get_contents($file))); file_put_contents($file,str_replace('769418130101000','769418130101000 AC Power Failure ',file_get_contents($file))); file_put_contents($file,str_replace('769418330101000','769418330101000 AC Power Restore ',file_get_contents($file))); ?>[/php]
The output from the above line is:
769418130101000 AC Power Failure B
How do I stop the 16th character/digit in this case “B” from showing up in the output???
Question/Example 2: For some alarms I can only search on the first 10 characters/digits of the 16 generated by the alarm as the last 6 are never the same.
The alarm generates the following Text file:
[metadata]
PROTOCOL=ADEMCO_CONTACT_ID
CALLINGFROM=5085551212
CALLERNAME=
TIMESTAMP=Wed Nov 21, 2012 @ 13:33:58 EST
[events]
7694181302123456
[php]
<?php $file = '/etc/asterisk/alarm/latest.txt'; // // System Alarms file_put_contents($file,str_replace('7694181110','7694181110 Fire Alarm ',file_get_contents($file))); file_put_contents($file,str_replace('7694183110','7694183110 Fire Alarm Clear ',file_get_contents($file))); file_put_contents($file,str_replace('7694181111','7694181111 Smoke Alarm ',file_get_contents($file))); file_put_contents($file,str_replace('7694183111','7694183111 Smoke Alarm Clear ',file_get_contents($file))); file_put_contents($file,str_replace('7694181302','7694181302 Low System Battery ',file_get_contents($file))); file_put_contents($file,str_replace('769418130101000','769418130101000 AC Power Failure ',file_get_contents($file))); file_put_contents($file,str_replace('769418330101000','769418330101000 AC Power Restore ',file_get_contents($file))); ?>[/php]
7694181302 Low System Battery 123456
How do i stop the last 6 digits/characters from showing up in the output?
The script needs to be looking for either scenerio
I am just learning php so please be as detailed as possible. Thanks very much for your help !!!