How can I use PHP to read the two characters in the first line of the TXT file for mathematical operations and output? if the hexadecimal data in the first line of the TXT file is: AA C0 ED 00 8A 01 BA 09 3B AB
How to use PHP to read the third character ED and fourth character 00
Convert them to decimal and perform mathematical operations.
Calculation formula: (OO * 256 + ED)/10
Display the calculation result on the page
Reply to discussion (solution)
// Assume that the data is read to the variable $ s = 'AA C0 ED 00 8A 01 BA 09 3B AB '; $ a = explode ('', $ s ); echo (hexdec ($ a [3]) * 256 + hexdec ($ a [2])/10;
23.7
How can we keep reading data from the first row?
I don't know what you're talking about.
This txt file will add a row per second, so I want him to read the data of the first row cyclically.
$ Handle = @ fopen ("/tmp/inputfile.txt", "r ");
If ($ handle ){
While (! Feof ($ handle )){
$ Buffer = fgets ($ handle, 4096 );
Echo $ buffer;
}
Fclose ($ handle );
}
In addition, strpos can be used to obtain characters at a specified position.
Sorry, the mistake should be caused by substr.
This txt file will add a row per second, so I want him to read the data of the first row cyclically.
Add a row per second. The data in the first row will not change.
Txt has been added. do you want to read the last row?
It is incorrect that the txt file will add a row at the bottom of the row per second. how can I read the data of the last row, and read the data every five seconds. Because dynamic results must be displayed on the page.
Last read-only row: $ txt = array_pop (file ('filename '));