Home  >  Article  >  Backend Development  >  Example of using php function to output XML file

Example of using php function to output XML file

WBOY
WBOYOriginal
2016-07-25 09:10:311014browse
  1. $conn= new PDO("mysql:dbname=lamp;host=localhost","root","123456");

  2. $sql="select id,username,phone,*** from user";

  3. $pdo=$conn->prepare($sql);
  4. $pdo->execute();
  5. $str='';
  6. $str.='';
  7. //如果内容中有html代码可以使用
  8. while(list($id,$username,$phone,$***)=$pdo->fetch(PDO::FETCH_NUM)){
  9. $str.='';
  10. $str.=''.$username.'';
  11. $str.=''.$phone.'';
  12. $str.='<***>'.$***.'';
  13. $str.='';
  14. }

  15. $str.='';

  16. file_put_contents("user.xml",$str);
  17. header("Content-type:text/xml");
  18. echo $str;
  19. ?>

复制代码


Statement:
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