1. Description of the problem
To capture the information you need on a fixed web page and store it in a tabular format. I took a list of wustoj to practice, address: Wustoj
2. Ideas
Web page itself simply learn PHP, just use it to do something, my idea is this:
(1) View the source code of the webpage and save it in the file.
(2) write the regular expression according to the required information, read the file, and extract the required information according to the regular expression. When writing regular expressions, it is best to group them so that they are easier to extract.
(3) For Excel operation, the extracted information is exported in Excel form.
Good open source PHP processing Excel Class Link: Click to open the link
3. Experience
^ refers to the beginning of the original string, which means that if the end of the original string.
A null character is not necessarily a space.
Grouping with () is a good method, such as Preg_macth_all (/$pattern/, $subject, matches).
Matches is a two-dimensional array, and if there is no _all, it will only match the first part, which is a one-dimensional array.
$matches [0] saves all matches for the full pattern. $matches [1] saves all matches of the first subgroup, that is, the first part of all matches.
Chinese match string I used this $PATT_CH=CHR (0x80). " -". Chr (0xFF).
4. Code
1
) ([0-9]+|\*) (
GetProperties ()->setcreator ("Maarten Balliauw"), $objPHPExcel->getproperties ()->setlastmodifiedby (" Maarten Balliauw "), $objPHPExcel->getproperties ()->settitle (" Office "XLSX Test Document"), $objPHPExcel- >getproperties ()->setsubject ("Office" XLSX Test Document "), $objPHPExcel->getproperties () SetDescription ("Test document for Office" XLSX, generated using PHP classes. "); $objPHPExcel->getproperties ()->setkeywords ("Office openxml PHP"), $objPHPExcel->getproperties () Setcategory ("Test result file"); $row =1; $objPHPExcel->getactivesheet ()->setcellvalue (' A '. $row, ' rank '); $ Objphpexcel->getactivesheet ()->setcellvalue (' B '. $row, ' team '); $objPHPExcel->getactivesheet () Setcellvalue (' C '. $row, ' solved '), while (!feof ($file)) {//echo $row. " "; $line =fgets ($file), if (Preg_match ("/$rankpatt/", $line, $match)) {$row ++;//print_r ($match);//echo$match[2]." ";//echo"
"; $objPHPExcel->getactivesheet ()->setcellvalue (' A '. $row, $match [2]); $objPHPExcel->getactivesheet ()- >getstyle (' A '. $row)->getalignment ()->sethorizontal (phpexcel_style_alignment::horizontal_left);} if (Preg_match ("/$namepatt/", $line, $match)) {//print_r ($match);//echo$match[2]. " ". $match [4]." ";//echo"
"; $objPHPExcel->getactivesheet ()->setcellvalue (' B '. $row, $match [2]. $match [4]);} if (Preg_match ("/$problempatt/", $line, $match)) {//print_r ($match);//echo$match[2]. " ";//echo"
"; $objPHPExcel->getactivesheet ()->setcellvalue (' C '). $row, $match [2]); $objPHPExcel->getactivesheet ()->getstyle (' C '. $row)->getalignment ()->sethorizontal ( Phpexcel_style_alignment::horizontal_left);} $objWriter = new phpexcel_writer_excel2007 ($objPHPExcel), $objWriter->save (Str_replace ('. php ', '. xlsx ', __file__) );} echo "Well-done:)";? >
5. Running Results