Script Language-A and B files. Use PHP scripts to output the content of A to B in A certain format. New php

Source: Internet
Author: User
The directory contains the directory a.logand B .txt. the source a.logsource file B .txt is written in php, And the content in the source file is output to. log content: 1.1 ^ A1452773009204 ^ B14670348 ^ cm_2000071003_21540... assume that the directory contains. log and B .txt
A. log source file
B .txt target file
The script is written in php to split the content in the source file into ^ A ^ B ^ C and output it to the target file.

The content in A. log is:
1.1 ^ A1452773009204 ^ B14670348 ^ cm_2000071003_21540002_21668001 ^ C ^ C15 ^ C ^ Bapp ^ C ^ C1: 201778e9036a8e37592c99441 ^ C ^ B1 ^ C56978e9036a8e37592c99441 ^ C1 ^ C ^ B ^ C ^ C1 ^ C0 ^ C ^ C0 ^ C ^ C48 ^ Bandroid ^ C ^ B ^ C ^ Ch5 ^ Bwifi ^ C ^ C10.62.50.235 ^ B ^ C ^ C1.0 ^ B ^ C ^ C ^ BMozilla/5.0 (Macintosh; intel Mac OS x 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36 ^ C ^ B ^ A ^ B

Hope you can advise

Reply content:

Assume that the directory contains A. log and B .txt texts.
A. log source file
B .txt target file
The script is written in php to split the content in the source file into ^ A ^ B ^ C and output it to the target file.

The content in A. log is:
1.1 ^ A1452773009204 ^ B14670348 ^ cm_2000071003_21540002_21668001 ^ C ^ C15 ^ C ^ Bapp ^ C ^ C1: 201778e9036a8e37592c99441 ^ C ^ B1 ^ C56978e9036a8e37592c99441 ^ C1 ^ C ^ B ^ C ^ C1 ^ C0 ^ C ^ C0 ^ C ^ C48 ^ Bandroid ^ C ^ B ^ C ^ Ch5 ^ Bwifi ^ C ^ C10.62.50.235 ^ B ^ C ^ C1.0 ^ B ^ C ^ C ^ BMozilla/5.0 (Macintosh; intel Mac OS x 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36 ^ C ^ B ^ A ^ B

Hope you can advise

Procedure
1. file_get_contents () Get the log source file content
2. preg_match_all () split the content into an array
3. Assemble your string in the desired format and add a line break or anything ~
4. file_put_contents () Output content to the txt file

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.