Php export the instance code of the word format document

Source: Internet
Author: User
Php export the instance code of the word format document

  1. /**

  2. * Export a word document
  3. * Add a keyword link only once
  4. * Edit bbs.it-home.org
  5. */
  6. // Var_dump ($ _ SERVER ["HTTPS"]); die;
  7. Class word
  8. {
  9. Function start ()
  10. {
  11. Ob_start ();
  12. Echo'Xmlns: w = "urn: schemas-microsoft-com: office: word"
  13. Xmlns = "http://www.w3.org/tr/rec-html40”> ';
  14. }

  15. Function save ($ path)

  16. {
  17. Print"";
  18. $ Data = ob_get_contents ();
  19. Ob_end_clean ();
  20. $ This-> wirtefile ($ path, $ data );
  21. }

  22. Function wirtefile ($ fn, $ data)

  23. {
  24. $ Fp = fopen ($ fn, "wb ");
  25. Fwrite ($ fp, $ data );
  26. Fclose ($ fp );
  27. }
  28. }
  29. $ Db = mysql_connect ('localhost', 'root', '000000') or die ("cocould not connect to database."); // connect to the database

  30. Mysql_select_db ('test'); // select a database

  31. $ SQL = "select info. itemid, info. title, info. tag, con. content from csign_info_22 as info left join csign_info_data_22 as con on con. itemid = info. itemid ";

  32. Mysql_query ('set names "utf8 ″');

  33. $ Res = mysql_query ($ SQL, $ db );

  34. While ($ info = mysql_fetch_array ($ res ))

  35. {
  36. If ($ info ['tag']) {
  37. $ Tagexp = explode ('', $ info ['tag']);
  38. Foreach ($ tagexp as $ k => $ v ){
  39. $ Tagstr. = 'http: // bbs.it-home.org/invest/search-htm-kw-'.w.v.'.html"> '. $ v .'';

  40. If (strpos ($ info ['content'], $ v )){

  41. $ Info ['content'] = str_replace_once ($ v, "http://bbs.it-home.org/invest/search-htm-kw-20..v.20..html target = _ blank>". $ v. ", $ info ['content']);
  42. }
  43. }
  44. }
  45. // Echo $ info ['content']; die;
  46. $ Html ='

    '. $ Info ['title'].'

    '. $ Info ['content'].'

    ';

  47. If ($ tagstr) {$ html. ='

    Keywords: '. $ tagstr .'

    ';}
  48. $ Html. ='

    This article is collected by http://bbs.it-home.org/"> programmer's home. For more information, visit http://bbs.it-home.org/"> Tiandone

    ';
  49. $ Word = new word ();
  50. $ Word-> start ();
  51. // $ Html = "aaa". $ I;
  52. $ Title = iconv ("UTF-8", "GB2312", $ info ['title']);
  53. // Echo $ title; die;
  54. $ Wordname = 'E:/web/paypal/product/tiandone/'.20.title.".doc "; // storage directory
  55. // Echo $ wordname; die;
  56. Echo $ html;
  57. $ Word-> save ($ wordname );
  58. Ob_flush (); // refresh the cache before each execution
  59. Flush ();
  60. // Print_r ($ info); die;
  61. // Die;
  62. }
  63. // Match only one duplicate keyword mismatch
  64. Function str_replace_once ($ needle, $ replace, $ haystack ){
  65. // Looks for the first occurence of $ needle in $ haystack
  66. // And replaces IT with $ replace.
  67. $ Pos = strpos ($ haystack, $ needle );
  68. If ($ pos = false ){
  69. // Nothing found
  70. Return $ haystack;
  71. }
  72. Return substr_replace ($ haystack, $ replace, $ pos, strlen ($ needle ));
  73. }
  74. ?>

The above is the code provided in today's php Tutorial for your study. If you want to learn php, come to the programmer's house.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.