I haven’t updated my blog for a while, for fear of being forgotten by Baidu, biu~biu~. Recently there was one The project needs to count the url and title of the website and save them in excel. The following is the specific code
<!--p</p> <p>//php generates excel reports by sending header() header information<br /> header("Content-Type: application/vnd.ms-execl"); <br /> header("Content-Type: application/vnd.ms-excel; charset=gb2312");<br /> //Inform the browser of the file name and ask the client to download <br /> header("Content-Disposition:filename=test.xls"); <br /> header("Pragma: no-cache"); <br /> header("Expires: 0");</p> <p>$link = mysql_connect('localhost', 'root', '') or die('Could not connect: ' . mysql_error());<br /> mysql_select_db('novartis') or die('Could not select database');</p> <p>mysql_query("SET NAMES gb2312");<br /> $query = 'SELECT title,keywords,url,description FROM cms_content';<br /> $result = mysql_query($query) or die('Query failed: ' . mysql_error());<br /> // Display results in HTML <br /> //$str =mb_convert_encoding ("Test 1", "gb2312", "utf-8"); <br /> echo "Title"; <br /> echo "Keywordst"; <br /> echo "Descriptiont"; <br /> echo "URLtn"; <br /> /* Format: Line break: "tn": Between cells: "t" */</p> <p>while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {<br /> echo $line['title']."t";<br /> echo $line['keywords']."t";<br /> echo $line['description']."t"; <br /> echo $line['url']."tn";</p> <p>}</p> <p><br /> // Release the result set<br /> mysql_free_result($result);<br /> //Close connection<br /> mysql_close($link);<br /> --><br>