/**
- * Export Word format documents
- * Add keyword links only once
- * Edit bbs.it-home.org
- */
- Var_dump ($_server["HTTPS"]);d ie;
- 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 ', ' 123123′ ' or Die ("Could not connect to database."); /Connection Database
mysql_select_db (' Test '); Select 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. = '. $v. ';
if (Strpos ($info [' content '], $v)) {
- $info [' content '] =str_replace_once ($v, "". $v. "", $info [' content ']);
- }
- }
- }
- echo $info [' content '];d ie;
- $html = '
'. $info [' title ']. ' '. $info [' content ']. ' ’;
if ($tagstr) {$html. = ' Keywords: '. $tagstr. ' ’;}
- $html. = '
This article is compiled by the programmer's home, please visit tiandone for more information. ’;
- $word = new Word ();
- $word->start ();
- $html = "AAA". $i;
- $title = Iconv ("Utf-8″," Gb2312″, $info [' title ']);
- echo $title;d ie;
- $wordname = ' e:/web/paypal/product/tiandone/'. $title. ". Doc ";//Store Directory
- echo $wordname;d ie;
- Echo $html;
- $word->save ($wordname);
- Ob_flush ();//flush cache before each execution
- Flush ();
- Print_r ($info);d ie;
- Die
- }
- Match only one keyword repeat 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));
- }
- ?>
Copy CodeThe above is the code for today's PHP tutorial, for everyone to learn the use of research. Learn PHP and come to the programmer's house. |