How can I use PHP to read the two characters in the first line of the TXT file for mathematical operations and output?

Source: Internet
Author: User
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 '));

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.