Php export the instance code of the word format document
/**
- * Export a word document
- * Add a keyword link only once
- * Edit bbs.it-home.org
- */
- // Var_dump ($ _ SERVER ["HTTPS"]); die;
- Class word
- {
- Function start ()
- {
- Ob_start ();
- Echo'Xmlns: w = "urn: schemas-microsoft-com: office: word"
- Xmlns = "http://www.w3.org/tr/rec-html40”> ';
- }
Function save ($ path)
- {
- Print"";
- $ Data = ob_get_contents ();
- Ob_end_clean ();
- $ This-> wirtefile ($ path, $ data );
- }
Function wirtefile ($ fn, $ data)
- {
- $ Fp = fopen ($ fn, "wb ");
- Fwrite ($ fp, $ data );
- Fclose ($ fp );
- }
- }
- $ Db = mysql_connect ('localhost', 'root', '000000') or die ("cocould not connect to database."); // connect to the database
Mysql_select_db ('test'); // select a database
- $ 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 ";
Mysql_query ('set names "utf8 ″');
- $ Res = mysql_query ($ SQL, $ db );
While ($ info = mysql_fetch_array ($ res ))
- {
- If ($ info ['tag']) {
- $ Tagexp = explode ('', $ info ['tag']);
- Foreach ($ tagexp as $ k => $ v ){
- $ Tagstr. = 'http: // bbs.it-home.org/invest/search-htm-kw-'.w.v.'.html"> '. $ v .'';
If (strpos ($ info ['content'], $ v )){
- $ Info ['content'] = str_replace_once ($ v, "http://bbs.it-home.org/invest/search-htm-kw-20..v.20..html target = _ blank>". $ v. ", $ info ['content']);
- }
- }
- }
- // Echo $ info ['content']; die;
- $ Html ='
'. $ Info ['title'].' '. $ Info ['content'].' ';
If ($ tagstr) {$ html. =' Keywords: '. $ tagstr .' ';}
- $ Html. ='
This article is collected by http://bbs.it-home.org/"> programmer's home. For more information, visit http://bbs.it-home.org/"> Tiandone ';
- $ Word = new word ();
- $ Word-> start ();
- // $ Html = "aaa". $ I;
- $ Title = iconv ("UTF-8", "GB2312", $ info ['title']);
- // Echo $ title; die;
- $ Wordname = 'E:/web/paypal/product/tiandone/'.20.title.".doc "; // storage directory
- // Echo $ wordname; die;
- Echo $ html;
- $ Word-> save ($ wordname );
- Ob_flush (); // refresh the cache before each execution
- Flush ();
- // Print_r ($ info); die;
- // Die;
- }
- // Match only one duplicate keyword mismatch
- Function str_replace_once ($ needle, $ replace, $ haystack ){
- // Looks for the first occurence of $ needle in $ haystack
- // And replaces IT with $ replace.
- $ Pos = strpos ($ haystack, $ needle );
- If ($ pos = false ){
- // Nothing found
- Return $ haystack;
- }
- Return substr_replace ($ haystack, $ replace, $ pos, strlen ($ needle ));
- }
- ?>
-
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. |