Use php regular expressions to remember data
- xml source file
-
-
-
- Zhang Ying
- Male
- 28
-
-
- tank
- Male sex>
- 28
-
-
-
- $xml = "";
- $f = fopen('person.xml', ' r');
- while( $data = fread( $f, 4096 ) ) {
- $xml .= $data;
- }
- fclose( $f );
- // Read the data above
- preg_match_all( "/< humans>(.*?)/s", $xml, $humans ); //Match the content in the outermost tag
-
- foreach( $humans[1] as $k=>$human )
- {
- preg_match_all( "/(.*?)/", $human, $name ); //Match the name
- preg_match_all( "/(.*? )/", $human, $sex ); //Match gender
- preg_match_all( "/(.*?)/", $human, $old ); //Match age
- }
-
- foreach($name[1] as $key=>$val){
- echo $val." - ".$sex[$key][1]." - ".$ old[$key][1]."
" ;
- }
- ?>
Copy code
|