A simple matching problem ----------- text ----------------- Name1ABCName2ABCName3ABC ------------- text ----------------- A, B, and C are three simple matching problems.
------------- Text ---------------
Name1 A B C
Name2 A B C
Name3 A B C
------------- Text ---------------
A, B, and C are three random numbers. Sometimes A number is null (that is, it becomes Name1 A C ), how can I obtain the value of ABC in any situation?
Thank you!
------ Solution --------------------
PHP code
$ S = <TXTName1 a B CName2 A CName3 a B CTXT; preg_match_all ('/([ABC] +) \ s + ([ABC] *) \ s + ([ABC] *) \ s * $/M', $ s, $ r); print_r ($ r );
------ Solution --------------------
Hey...
A. php
------------- Text ---------------
Name1 11 23 14
Name2 43 33
Name3 30 44 2
------------- Text ---------------
B. php
$ File = "a. php"; // variable assignment
$ Fp = fopen ($ file, "r"); // open the file in read-only mode
$ I = 0; // I = 0
While (! Feof ($ fp) {// while loop, condition: not to the end of the file.
$ Buffer = fgets ($ fp, 4096); // The fgets () function is used to read files row-by-row from files, the number of bytes read. The default value is 1024 bytes.
Preg_replace ('/+/', '', $ buffer );
Preg_match_all ('/([0-9] +)/', $ buffer, $ matches );
If (! Empty ($ matches [1]) {
Print_r ($ matches [1]);
}
$ I = $ I + 1; // uses the while loop to increase the I value and build an array.
}
Fclose ($ fp); // close the file.
?>
------ Solution --------------------
In fact, I think there is another big question! Because LZ requires numbers and letters, such:
Text:
Name1: 11 32
What I finally got is
PHP code
Array( [0]=11 [1]= [2]=32)