Method 3 of reading xml in php---using php regular expressions to remember data

WBOY
Release: 2016-07-25 09:10:49
Original
836 people have browsed it
Use php regular expressions to remember data
  1. xml source file
  2. Zhang Ying
  3. Male
  4. 28
  5. tank
  6. Male
  7. 28
  8. $xml = "";
  9. $f = fopen('person.xml', ' r');
  10. while( $data = fread( $f, 4096 ) ) {
  11. $xml .= $data;
  12. }
  13. fclose( $f );
  14. // Read the data above
  15. preg_match_all( "/< humans>(.*?)/s", $xml, $humans ); //Match the content in the outermost tag
  16. foreach( $humans[1] as $k=>$human )
  17. {
  18. preg_match_all( "/(.*?)/", $human, $name ); //Match the name
  19. preg_match_all( "/(.*? )/", $human, $sex ); //Match gender
  20. preg_match_all( "/(.*?)/", $human, $old ); //Match age
  21. }
  22. foreach($name[1] as $key=>$val){
  23. echo $val." - ".$sex[$key][1]." - ".$ old[$key][1]."
    " ;
  24. }
  25. ?>
Copy code


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template