<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<?xml-stylesheet type="text/xsl" href="css/rss.xslt"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>YONGHUI'S BLOG</title><link>http://www.yonghui.net/</link><description>欢迎访问！永辉的个人BLOG。</description><generator>RainbowSoft Studio Z-Blog 1.8 Walle Build 100427</generator><language>zh-CN</language><copyright>Copyright 2001-2009 Yonghui.net Some Rights Reserved. 陕ICP备05002130号</copyright><pubDate>Fri, 18 Feb 2011 16:28:58 +0800</pubDate><item><title>21个实用便利的PHP代码</title><author>a@b.com (yonghui)</author><link>http://www.yonghui.net/post/10.html</link><pubDate>Fri, 18 Feb 2011 16:27:48 +0800</pubDate><guid>http://www.yonghui.net/post/10.html</guid><description><![CDATA[<p>1. PHP可阅读随机字符串<br />此代码将创建一个可阅读的字符串，使其更接近词典中的单词，实用且具有密码验证功能。</p><p>/**************<br />*@length - length of random string (must be a multiple of 2)<br />**************/<br />function readable_random_string($length = 6){<br />$conso=array(&quot;b&quot;,&quot;c&quot;,&quot;d&quot;,&quot;f&quot;,&quot;g&quot;,&quot;h&quot;,&quot;j&quot;,&quot;k&quot;,&quot;l&quot;,<br />&quot;m&quot;,&quot;n&quot;,&quot;p&quot;,&quot;r&quot;,&quot;s&quot;,&quot;t&quot;,&quot;v&quot;,&quot;w&quot;,&quot;x&quot;,&quot;y&quot;,&quot;z&quot;);<br />$vocal=array(&quot;a&quot;,&quot;e&quot;,&quot;i&quot;,&quot;o&quot;,&quot;u&quot;);<br />$password=&quot;&quot;;<br />srand ((double)microtime()*1000000);<br />$max = $length/2;<br />for($i=1; $i&lt;=$max; $i++)<br />{<br />$password.=$conso[rand(0,19)];<br />$password.=$vocal[rand(0,4)];<br />}<br />return $password;<br />}<br />2. PHP生成一个随机字符串<br />如果不需要可阅读的字符串，使用此函数替代，即可创建一个随机字符串，作为用户的随机密码等。</p><p>/*************<br />*@l - length of random string<br />*/<br />function generate_rand($l){<br />$c= &quot;ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789&quot;;<br />srand((double)microtime()*1000000);<br />for($i=0; $i&lt;$l; $i++) {<br />$rand.= $c[rand()%strlen($c)];<br />}<br />return $rand;<br />}3. PHP编码电子邮件地址<br />使用此代码，可以将任何电子邮件地址编码为 html 字符实体，以防止被垃圾邮件程序收集。</p><p>function encode_email($email='info@domain.com', $linkText='Contact Us', $attrs ='class=&quot;emailencoder&quot;' )<br />{<br />// remplazar aroba y puntos<br />$email = str_replace('@', '&amp;#64;', $email);<br />$email = str_replace('.', '&amp;#46;', $email);<br />$email = str_split($email, 5);</p><p>$linkText = str_replace('@', '&amp;#64;', $linkText);<br />$linkText = str_replace('.', '&amp;#46;', $linkText);<br />$linkText = str_split($linkText, 5);</p><p>$part1 = '&lt;a href=&quot;ma';<br />$part2 = 'ilto&amp;#58;';<br />$part3 = '&quot; '. $attrs .' &gt;';<br />$part4 = '&lt;/a&gt;';</p><p>$encoded = '&lt;script type=&quot;text/javascript&quot;&gt;';<br />$encoded .= &quot;document.write('$part1');&quot;;<br />$encoded .= &quot;document.write('$part2');&quot;;<br />foreach($email as $e)<br />{<br />$encoded .= &quot;document.write('$e');&quot;;<br />}<br />$encoded .= &quot;document.write('$part3');&quot;;<br />foreach($linkText as $l)<br />{<br />$encoded .= &quot;document.write('$l');&quot;;<br />}<br />$encoded .= &quot;document.write('$part4');&quot;;<br />$encoded .= '&lt;/script&gt;';</p><p>return $encoded;<br />}4. PHP验证邮件地址<br />电子邮件验证也许是中最常用的网页表单验证，此代码除了验证电子邮件地址，也可以选择检查邮件域所属 DNS 中的 MX 记录，使邮件验证功能更加强大。</p><p>function is_valid_email($email, $test_mx = false)<br />{<br />if(eregi(&quot;^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$&quot;, $email))<br />if($test_mx)<br />{<br />list($username, $domain) = split(&quot;@&quot;, $email);<br />return getmxrr($domain, $mxrecords);<br />}<br />else<br />return true;<br />else<br />return false;<br />}5. PHP列出目录内容<br />function list_files($dir)<br />{<br />if(is_dir($dir))<br />{<br />if($handle = opendir($dir))<br />{<br />while(($file = readdir($handle)) !== false)<br />{<br />if($file != &quot;.&quot; &amp;&amp; $file != &quot;..&quot; &amp;&amp; $file != &quot;Thumbs.db&quot;)<br />{<br />echo '&lt;a target=&quot;_blank&quot; href=&quot;'.$dir.$file.'&quot;&gt;'.$file.'&lt;/a&gt;&lt;br&gt;'.&quot;\n&quot;;<br />}<br />}<br />closedir($handle);<br />}<br />}<br />}6. PHP销毁目录<br />删除一个目录，包括它的内容。</p><p>/*****<br />*@dir - Directory to destroy<br />*@virtual[optional]- whether a virtual directory<br />*/<br />function destroyDir($dir, $virtual = false)<br />{<br />$ds = DIRECTORY_SEPARATOR;<br />$dir = $virtual ? realpath($dir) : $dir;<br />$dir = substr($dir, -1) == $ds ? substr($dir, 0, -1) : $dir;<br />if (is_dir($dir) &amp;&amp; $handle = opendir($dir))<br />{<br />while ($file = readdir($handle))<br />{<br />if ($file == '.' || $file == '..')<br />{<br />continue;<br />}<br />elseif (is_dir($dir.$ds.$file))<br />{<br />destroyDir($dir.$ds.$file);<br />}<br />else<br />{<br />unlink($dir.$ds.$file);<br />}<br />}<br />closedir($handle);<br />rmdir($dir);<br />return true;<br />}<br />else<br />{<br />return false;<br />}<br />}7. PHP解析 JSON 数据<br />与大多数流行的 Web 服务如 twitter 通过开放 API 来提供数据一样，它总是能够知道如何解析 API 数据的各种传送格式，包括 JSON，XML 等等。</p><p>$json_string='{&quot;id&quot;:1,&quot;name&quot;:&quot;foo&quot;,&quot;email&quot;:&quot;foo@foobar.com&quot;,&quot;interest&quot;:[&quot;wordpress&quot;,&quot;php&quot;]} ';<br />$obj=json_decode($json_string);<br />echo $obj-&gt;name; //prints foo<br />echo $obj-&gt;interest[1]; //prints php8. PHP解析 XML 数据<br />//xml string<br />$xml_string=&quot;&lt;?xml version='1.0'?&gt;<br />&lt;users&gt;<br />&lt;user id='398'&gt;<br />&lt;name&gt;Foo&lt;/name&gt;<br />&lt;email&gt;foo@bar.com&lt;/name&gt;<br />&lt;/user&gt;<br />&lt;user id='867'&gt;<br />&lt;name&gt;Foobar&lt;/name&gt;<br />&lt;email&gt;foobar@foo.com&lt;/name&gt;<br />&lt;/user&gt;<br />&lt;/users&gt;&quot;;</p><p>//load the xml string using simplexml<br />$xml = simplexml_load_string($xml_string);</p><p>//loop through the each node of user<br />foreach ($xml-&gt;user as $user)<br />{<br />//access attribute<br />echo $user['id'], ' ';<br />//subnodes are accessed by -&gt; operator<br />echo $user-&gt;name, ' ';<br />echo $user-&gt;email, '&lt;br /&gt;';<br />}9. PHP创建日志缩略名<br />创建用户友好的日志缩略名。</p><p>function create_slug($string){<br />$slug=preg_replace('/[^A-Za-z0-9-]+/', '-', $string);<br />return $slug;<br />}10. PHP获取客户端真实 IP 地址<br />该函数将获取用户的真实 IP 地址，即便他使用代理服务器。</p><p>function getRealIpAddr()<br />{<br />if (!emptyempty($_SERVER['HTTP_CLIENT_IP']))<br />{<br />$ip=$_SERVER['HTTP_CLIENT_IP'];<br />}<br />elseif (!emptyempty($_SERVER['HTTP_X_FORWARDED_FOR']))<br />//to check ip is pass from proxy<br />{<br />$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];<br />}<br />else<br />{<br />$ip=$_SERVER['REMOTE_ADDR'];<br />}<br />return $ip;<br />}11. PHP强制性文件下载<br />为用户提供强制性的文件下载功能。</p><p>/********************<br />*@file - path to file<br />*/<br />function force_download($file)<br />{<br />if ((isset($file))&amp;&amp;(file_exists($file))) {<br />header(&quot;Content-length: &quot;.filesize($file));<br />header('Content-Type: application/octet-stream');<br />header('Content-Disposition: attachment; filename=&quot;' . $file . '&quot;');<br />readfile(&quot;$file&quot;);<br />} else {<br />echo &quot;No file selected&quot;;<br />}<br />}12. PHP创建标签云<br />function getCloud( $data = array(), $minFontSize = 12, $maxFontSize = 30 )<br />{<br />$minimumCount = min( array_values( $data ) );<br />$maximumCount = max( array_values( $data ) );<br />$spread = $maximumCount - $minimumCount;<br />$cloudHTML = '';<br />$cloudTags = array();</p><p>$spread == 0 &amp;&amp; $spread = 1;</p><p>foreach( $data as $tag =&gt; $count )<br />{<br />$size = $minFontSize + ( $count - $minimumCount )<br />* ( $maxFontSize - $minFontSize ) / $spread;<br />$cloudTags[] = '&lt;a style=&quot;font-size: ' . floor( $size ) . 'px'<br />. '&quot; href=&quot;#&quot; title=&quot;\'' . $tag .<br />'\' returned a count of ' . $count . '&quot;&gt;'<br />. htmlspecialchars( stripslashes( $tag ) ) . '&lt;/a&gt;';<br />}</p><p>return join( &quot;\n&quot;, $cloudTags ) . &quot;\n&quot;;<br />}<br />/**************************<br />**** Sample usage ***/<br />$arr = Array('Actionscript' =&gt; 35, 'Adobe' =&gt; 22, 'Array' =&gt; 44, 'Background' =&gt; 43,<br />'Blur' =&gt; 18, 'Canvas' =&gt; 33, 'Class' =&gt; 15, 'Color Palette' =&gt; 11, 'Crop' =&gt; 42,<br />'Delimiter' =&gt; 13, 'Depth' =&gt; 34, 'Design' =&gt; 8, 'Encode' =&gt; 12, 'Encryption' =&gt; 30,<br />'Extract' =&gt; 28, 'Filters' =&gt; 42);<br />echo getCloud($arr, 12, 36);13. PHP寻找两个字符串的相似性<br />PHP 提供了一个极少使用的 similar_text 函数，但此函数非常有用，用于比较两个字符串并返回相似程度的百分比。</p><p>similar_text($string1, $string2, $percent);<br />//$percent will have the percentage of similarity14. PHP在应用程序中使用 Gravatar 通用头像<br />随着 WordPress 越来越普及，Gravatar 也随之流行。由于 Gravatar 提供了易于使用的 API，将其纳入应用程序也变得十分方便。</p><p>/******************<br />*@email - Email address to show gravatar for<br />*@size - size of gravatar<br />*@default - URL of default gravatar to use<br />*@rating - rating of Gravatar(G, PG, R, X)<br />*/<br />function show_gravatar($email, $size, $default, $rating)<br />{<br />echo '&lt;img src=&quot;http://www.gravatar.com/avatar.php?gravatar_id='.md5($email).<br />'&amp;default='.$default.'&amp;size='.$size.'&amp;rating='.$rating.'&quot; width=&quot;'.$size.'px&quot;<br />height=&quot;'.$size.'px&quot; /&gt;';<br />}15. PHP在字符断点处截断文字<br />所谓断字 (word break)，即一个单词可在转行时断开的地方。这一函数将在断字处截断字符串。</p><p>// Original PHP code by Chirp Internet: www.chirp.com.au<br />// Please acknowledge use of this code by including this header.<br />function myTruncate($string, $limit, $break=&quot;.&quot;, $pad=&quot;...&quot;) {<br />// return with no change if string is shorter than $limit<br />if(strlen($string) &lt;= $limit)<br />return $string;</p><p>// is $break present between $limit and the end of the string?<br />if(false !== ($breakpoint = strpos($string, $break, $limit))) {<br />if($breakpoint &lt; strlen($string) - 1) {<br />$string = substr($string, 0, $breakpoint) . $pad;<br />}<br />}<br />return $string;<br />}<br />/***** Example ****/<br />$short_string=myTruncate($long_string, 100, ' ');16. PHP文件 Zip 压缩<br />/* creates a compressed zip file */<br />function create_zip($files = array(),$destination = '',$overwrite = false) {<br />//if the zip file already exists and overwrite is false, return false<br />if(file_exists($destination) &amp;&amp; !$overwrite) { return false; }<br />//vars<br />$valid_files = array();<br />//if files were passed in...<br />if(is_array($files)) {<br />//cycle through each file<br />foreach($files as $file) {<br />//make sure the file exists<br />if(file_exists($file)) {<br />$valid_files[] = $file;<br />}<br />}<br />}<br />//if we have good files...<br />if(count($valid_files)) {<br />//create the archive<br />$zip = new ZipArchive();<br />if($zip-&gt;open($destination,$overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) {<br />return false;<br />}<br />//add the files<br />foreach($valid_files as $file) {<br />$zip-&gt;addFile($file,$file);<br />}<br />//debug<br />//echo 'The zip archive contains ',$zip-&gt;numFiles,' files with a status of ',$zip-&gt;status;</p><p>//close the zip -- done!<br />$zip-&gt;close();</p><p>//check to make sure the file exists<br />return file_exists($destination);<br />}<br />else<br />{<br />return false;<br />}<br />}<br />/***** Example Usage ***/<br />$files=array('file1.jpg', 'file2.jpg', 'file3.gif');<br />create_zip($files, 'myzipfile.zip', true);17. PHP解压缩 Zip 文件<br />/**********************<br />*@file - path to zip file<br />*@destination - destination directory for unzipped files<br />*/<br />function unzip_file($file, $destination){<br />// create object<br />$zip = new ZipArchive() ;<br />// open archive<br />if ($zip-&gt;open($file) !== TRUE) {<br />die (&rsquo;Could not open archive&rsquo;);<br />}<br />// extract contents to destination directory<br />$zip-&gt;extractTo($destination);<br />// close archive<br />$zip-&gt;close();<br />echo 'Archive extracted to directory';<br />}18. PHP为 URL 地址预设 http 字符串<br />有时需要接受一些表单中的网址输入，但用户很少添加 http:// 字段，此代码将为网址添加该字段。</p><p>if (!preg_match(&quot;/^(http|ftp):/&quot;, $_POST['url'])) {<br />$_POST['url'] = 'http://'.$_POST['url'];<br />}19. PHP将网址字符串转换成超级链接<br />该函数将 URL 和 E-mail 地址字符串转换为可点击的超级链接。</p><p>function makeClickableLinks($text) {<br />$text = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_+.~#?&amp;//=]+)',<br />'&lt;a href=&quot;\1&quot;&gt;\1&lt;/a&gt;', $text);<br />$text = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_+.~#?&amp;//=]+)',<br />'\1&lt;a href=&quot;http://\2&quot;&gt;\2&lt;/a&gt;', $text);<br />$text = eregi_replace('([_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,3})',<br />'&lt;a href=&quot;mailto:\1&quot;&gt;\1&lt;/a&gt;', $text);</p><p>return $text;<br />}20. PHP调整图像尺寸<br />创建图像缩略图需要许多时间，此代码将有助于了解缩略图的逻辑。</p><p>/**********************<br />*@filename - path to the image<br />*@tmpname - temporary path to thumbnail<br />*@xmax - max width<br />*@ymax - max height<br />*/<br />function resize_image($filename, $tmpname, $xmax, $ymax)<br />{<br />$ext = explode(&quot;.&quot;, $filename);<br />$ext = $ext[count($ext)-1];</p><p>if($ext == &quot;jpg&quot; || $ext == &quot;jpeg&quot;)<br />$im = imagecreatefromjpeg($tmpname);<br />elseif($ext == &quot;png&quot;)<br />$im = imagecreatefrompng($tmpname);<br />elseif($ext == &quot;gif&quot;)<br />$im = imagecreatefromgif($tmpname);</p><p>$x = imagesx($im);<br />$y = imagesy($im);</p><p>if($x &lt;= $xmax &amp;&amp; $y &lt;= $ymax)<br />return $im;</p><p>if($x &gt;= $y) {<br />$newx = $xmax;<br />$newy = $newx * $y / $x;<br />}<br />else {<br />$newy = $ymax;<br />$newx = $x / $y * $newy;<br />}</p><p>$im2 = imagecreatetruecolor($newx, $newy);<br />imagecopyresized($im2, $im, 0, 0, 0, 0, floor($newx), floor($newy), $x, $y);<br />return $im2;<br />}21. PHP检测 ajax 请求<br />大多数的 JavaScript 框架如 jquery，Mootools 等，在发出 Ajax 请求时，都会发送额外的 HTTP_X_REQUESTED_WITH 头部信息，头当他们一个ajax请求，因此你可以在服务器端侦测到 Ajax 请求。</p><p>if(!emptyempty($_SERVER['HTTP_X_REQUESTED_WITH']) &amp;&amp; strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'){<br />//If AJAX Request Then<br />}else{<br />//something else<br />}</p>]]></description><category>学习笔记</category><comments>http://www.yonghui.net/post/10.html#comment</comments><wfw:comment>http://www.yonghui.net/</wfw:comment><wfw:commentRss>http://www.yonghui.net/feed.asp?cmt=10</wfw:commentRss><trackback:ping>http://www.yonghui.net/cmd.asp?act=tb&amp;id=10&amp;key=37f4d4c6</trackback:ping></item><item><title>php的几个有用的小东西</title><author>a@b.com (yonghui)</author><link>http://www.yonghui.net/post/9.html</link><pubDate>Wed, 16 Feb 2011 10:51:50 +0800</pubDate><guid>http://www.yonghui.net/post/9.html</guid><description><![CDATA[<div><div style="font-size: 12px">1、关于PHP重定向<br />方法一：header(&quot;Location: index.php&quot;);<br />方法二：echo &quot;&lt;script&gt;window.location =\&quot;$PHP_SELF\&quot;;&lt;/script&gt;&quot;;<br />方法三：echo &quot;&lt;META HTTPEQUIV=\&quot;Refresh\&quot; CONTENT=\&quot;0; URL=index.php\&quot;&gt;&quot;;<br /><br />2、获取访问者浏览器<br />function browse_infor() <br />{<br />$browser=&quot;&quot;;$browserver=&quot;&quot;;<br />$Browsers =array(&quot;Lynx&quot;,&quot;MOSAIC&quot;,&quot;AOL&quot;,&quot;Opera&quot;,&quot;JAVA&quot;,&quot;MacWeb&quot;,&quot;WebExplorer&quot;,&quot;OmniWeb&quot;);<br />$Agent = $GLOBALS[&quot;HTTP_USER_AGENT&quot;];<br />for ($i=0; $i&lt;=7; $i&nbsp;&nbsp; ) <br />{<br />if (strpos($Agent,$Browsers[$i])) <br />{<br />$browser = $Browsers[$i];<br />$browserver =&quot;&quot;;<br />}<br />}<br />if (ereg(&quot;Mozilla&quot;,$Agent) &amp;;amp;&amp;;amp; !ereg(&quot;MSIE&quot;,$Agent)) <br />{<br />$temp =explode(&quot;(&quot;, $Agent); $Part=$temp[0];<br />$temp =explode(&quot;/&quot;, $Part); $browserver=$temp[1];<br />$temp =explode(&quot; &quot;,$browserver); $browserver=$temp[0];<br />$browserver =preg_replace(&quot;/([\d\.] )/&quot;,&quot;\1&quot;,$browserver);<br />$browserver = &quot; $browserver&quot;;<br />$browser = &quot;Netscape Navigator&quot;;<br />}<br />if (ereg(&quot;Mozilla&quot;,$Agent) &amp;;amp;&amp;;amp; ereg(&quot;Opera&quot;,$Agent)) <br />{<br />$temp =explode(&quot;(&quot;, $Agent); $Part=$temp[1];<br />$temp =explode(&quot;)&quot;, $Part); $browserver=$temp[1];<br />$temp =explode(&quot; &quot;,$browserver);$browserver=$temp[2];<br />$browserver =preg_replace(&quot;/([\d\.] )/&quot;,&quot;\1&quot;,$browserver);<br />$browserver = &quot; $browserver&quot;;<br />$browser = &quot;Opera&quot;;<br />}<br />if (ereg(&quot;Mozilla&quot;,$Agent) &amp;;amp;&amp;;amp; ereg(&quot;MSIE&quot;,$Agent)) <br />{<br />$temp = explode(&quot;(&quot;, $Agent); $Part=$temp[1];<br />$temp = explode(&quot;;&quot;,$Part); $Part=$temp[1];<br />$temp = explode(&quot; &quot;,$Part);$browserver=$temp[2];<br />$browserver =preg_replace(&quot;/([\d\.] )/&quot;,&quot;\1&quot;,$browserver);<br />$browserver = &quot; $browserver&quot;;<br />$browser = &quot;Internet Explorer&quot;;<br />}<br />if ($browser!=&quot;&quot;) <br />{<br />$browseinfo = &quot;$browser$browserver&quot;;<br />}<br />else <br />{<br />$browseinfo = &quot;Unknown&quot;;<br />}<br />return $browseinfo;<br />}<br />//调用方法$browser=browseinfo() ;直接返回结果<br /><br />3、获取访问者操作系统<br />function osinfo() {<br />$os=&quot;&quot;;<br />$Agent = $GLOBALS[&quot;HTTP_USER_AGENT&quot;];<br />if (eregi('win',$Agent) &amp;;amp;&amp;;amp; strpos($Agent, '95')) {<br />$os=&quot;Windows 95&quot;;<br />}<br />elseif (eregi('win 9x',$Agent) &amp;;amp;&amp;;amp; strpos($Agent, '4.90')) {<br />$os=&quot;Windows ME&quot;;<br />}<br />elseif (eregi('win',$Agent) &amp;;amp;&amp;;amp; ereg('98',$Agent)) {<br />$os=&quot;Windows 98&quot;;<br />}<br />elseif (eregi('win',$Agent) &amp;;amp;&amp;;amp; eregi('nt 5\.0',$Agent)) { <br />$os=&quot;Windows 2000&quot;; <br />}<br />elseif (eregi('win',$Agent) &amp;;amp;&amp;;amp; eregi('nt',$Agent)) {<br />$os=&quot;Windows NT&quot;;<br />}<br />elseif (eregi('win',$Agent) &amp;;amp;&amp;;amp; eregi('nt 5\.1',$Agent)) { <br />$os=&quot;Windows XP&quot;; <br />} <br />elseif (eregi('win',$Agent) &amp;;amp;&amp;;amp; ereg('32',$Agent)) {<br />$os=&quot;Windows 32&quot;;<br />}<br />elseif (eregi('linux',$Agent)) {<br />$os=&quot;Linux&quot;;<br />}<br />elseif (eregi('unix',$Agent)) {<br />$os=&quot;Unix&quot;;<br />}<br />elseif (eregi('sun',$Agent) &amp;;amp;&amp;;amp; eregi('os',$Agent)) {<br />$os=&quot;SunOS&quot;;<br />}<br />elseif (eregi('ibm',$Agent) &amp;;amp;&amp;;amp; eregi('os',$Agent)) {<br />$os=&quot;IBM OS/2&quot;;<br />}<br />elseif (eregi('Mac',$Agent) &amp;;amp;&amp;;amp; eregi('PC',$Agent)) {<br />$os=&quot;Macintosh&quot;;<br />}<br />elseif (eregi('PowerPC',$Agent)) {<br />$os=&quot;PowerPC&quot;;<br />}<br />elseif (eregi('AIX',$Agent)) {<br />$os=&quot;AIX&quot;;<br />}<br />elseif (eregi('HPUX',$Agent)) {<br />$os=&quot;HPUX&quot;;<br />}<br />elseif (eregi('NetBSD',$Agent)) {<br />$os=&quot;NetBSD&quot;;<br />}<br />elseif (eregi('BSD',$Agent)) {<br />$os=&quot;BSD&quot;;<br />}<br />elseif (ereg('OSF1',$Agent)) {<br />$os=&quot;OSF1&quot;;<br />}<br />elseif (ereg('IRIX',$Agent)) {<br />$os=&quot;IRIX&quot;;<br />}<br />elseif (eregi('FreeBSD',$Agent)) {<br />$os=&quot;FreeBSD&quot;;<br />}<br />if ($os=='') $os = &quot;Unknown&quot;;<br />return $os;<br />}<br />//调用方法$os=os_infor() ;<br /><br />4、文件格式类<br />$mime_types = array( <br />'gif' =&gt; 'image/gif', <br />'jpg' =&gt; 'image/jpeg', <br />'jpeg' =&gt; 'image/jpeg', <br />'jpe' =&gt; 'image/jpeg', <br />'bmp' =&gt; 'image/bmp', <br />'png' =&gt; 'image/png', <br />'tif' =&gt; 'image/tiff', <br />'tiff' =&gt; 'image/tiff', <br />'pict' =&gt; 'image/xpict', <br />'pic' =&gt; 'image/xpict', <br />'pct' =&gt; 'image/xpict', <br />'tif' =&gt; 'image/tiff', <br />'tiff' =&gt; 'image/tiff', <br />'psd' =&gt; 'image/xphotoshop', <br /><br />'swf' =&gt; 'application/xshockwaveflash', <br />'js' =&gt; 'application/xjavascript', <br />'pdf' =&gt; 'application/pdf', <br />'ps' =&gt; 'application/postscript', <br />'eps' =&gt; 'application/postscript', <br />'ai' =&gt; 'application/postscript', <br />'wmf' =&gt; 'application/xmsmetafile', <br /><br />'css' =&gt; 'text/css', <br />'htm' =&gt; 'text/html', <br />'html' =&gt; 'text/html', <br />'txt' =&gt; 'text/plain', <br />'xml' =&gt; 'text/xml', <br />'wml' =&gt; 'text/wml', <br />'wbmp' =&gt; 'image/vnd.wap.wbmp', <br /><br />'mid' =&gt; 'audio/midi', <br />'wav' =&gt; 'audio/wav', <br />'mp3' =&gt; 'audio/mpeg', <br />'mp2' =&gt; 'audio/mpeg', <br /><br />'avi' =&gt; 'video/xmsvideo', <br />'mpeg' =&gt; 'video/mpeg', <br />'mpg' =&gt; 'video/mpeg', <br />'qt' =&gt; 'video/quicktime', <br />'mov' =&gt; 'video/quicktime', <br /><br />'lha' =&gt; 'application/xlha', <br />'lzh' =&gt; 'application/xlha', <br />'z' =&gt; 'application/xcompress', <br />'gtar' =&gt; 'application/xgtar', <br />'gz' =&gt; 'application/xgzip', <br />'gzip' =&gt; 'application/xgzip', <br />'tgz' =&gt; 'application/xgzip', <br />'tar' =&gt; 'application/xtar', <br />'bz2' =&gt; 'application/bzip2', <br />'zip' =&gt; 'application/zip', <br />'arj' =&gt; 'application/xarj', <br />'rar' =&gt; 'application/xrarcompressed', <br /><br />'hqx' =&gt; 'application/macbinhex40', <br />'sit' =&gt; 'application/xstuffit', <br />'bin' =&gt; 'application/xmacbinary', <br /><br />'uu' =&gt; 'text/xuuencode', <br />'uue' =&gt; 'text/xuuencode', <br /><br />'latex'=&gt; 'application/xlatex', <br />'ltx' =&gt; 'application/xlatex', <br />'tcl' =&gt; 'application/xtcl', <br /><br />'pgp' =&gt; 'application/pgp', <br />'asc' =&gt; 'application/pgp', <br />'exe' =&gt; 'application/xmsdownload', <br />'doc' =&gt; 'application/msword', <br />'rtf' =&gt; 'application/rtf', <br />'xls' =&gt; 'application/vnd.msexcel', <br />'ppt' =&gt; 'application/vnd.mspowerpoint', <br />'mdb' =&gt; 'application/xmsaccess', <br />'wri' =&gt; 'application/xmswrite', <br />);<br />5、php生成excel文档<br />&lt;?<br />header(&quot;Contenttype:application/vnd.msexcel&quot;);<br />header(&quot;ContentDisposition:filename=test.xls&quot;);<br />echo &quot;test1\t&quot;;<br />echo &quot;test2\t\n&quot;;<br />echo &quot;test1\t&quot;;<br />echo &quot;test2\t\n&quot;;<br />echo &quot;test1\t&quot;;<br />echo &quot;test2\t\n&quot;;<br />echo &quot;test1\t&quot;;<br />echo &quot;test2\t\n&quot;;<br />echo &quot;test1\t&quot;;<br />echo &quot;test2\t\n&quot;;<br />echo &quot;test1\t&quot;;<br />echo &quot;test2\t\n&quot;;<br />?&gt;<br />//改动相应文件头就可以输出.doc .xls等文件格式了</div></div>]]></description><category>学习笔记</category><comments>http://www.yonghui.net/post/9.html#comment</comments><wfw:comment>http://www.yonghui.net/</wfw:comment><wfw:commentRss>http://www.yonghui.net/feed.asp?cmt=9</wfw:commentRss><trackback:ping>http://www.yonghui.net/cmd.asp?act=tb&amp;id=9&amp;key=8da43721</trackback:ping></item><item><title>用CSS控制超链接文字样式</title><author>a@b.com (yonghui)</author><link>http://www.yonghui.net/post/8.html</link><pubDate>Fri, 23 Jul 2010 12:57:17 +0800</pubDate><guid>http://www.yonghui.net/post/8.html</guid><description><![CDATA[<p>用CSS控制超链接样式-css超链接</p><p>&nbsp;</p><p>本文将讲解通过css样式或通过css来控制超链接样式。这里主要讲文字类型的超链接，超链接的样式包括通过CSS来控制设置超链接有无下划线、超链接文字颜色等样式。</p><p><br />什么是超链接？<br />超链接通俗地指从一个网页指向一个目标的连接关系,这个目标可以是另一个网页,也可以是相同网页上的不同位置，还可以是一个图片，一个电子邮件地址，一个文件，甚至是一个应用程序。而在一个网页中用来超链接的对象，可以是一段文本或者是一个图片。当浏览者单击已经链接的文字或图片后,链接目标将显示在浏览器上，并且根据目标的类型来打开或运行。 <br />超链接的代码<br />&lt;a href=&quot;http://www.divcss5.com/&quot; target=&quot;_blank&quot; title=&quot;关于div css的网站&quot;&gt;DIV+CSS&lt;/a&gt;<br />解析如下：<br />href 后跟被链接地址目标网站地址这里是http://www.divcss5.com/<br />target <br />_blank -- 在新窗口中打开链接 <br />_parent -- 在父窗体中打开链接 <br />_self -- 在当前窗体打开链接,此为默认值 <br />_top -- 在当前窗体打开链接，并替换当前的整个窗体(框架页)</p><p><br />title 后跟链接目标说明，也就是超链接被链接网址情况简要说明，或标题</p><p><br />CSS可控制超链接样式-css链接样式如下<br />a:active是超级链接的初始状态 <br />a:hover是把鼠标放上去时的状况 <br />a:link 是鼠标点击时 <br />a:visited是访问过后的情况</p><p><br />超链接样式案例<br />1、通常对全站超链接样式化方法<br />a{color:#333;text-decoration:none; } //对全站有链接的文字颜色样式为color:#333;并立即无下划线text-decoration:none;<br />a:hover {color:#CC3300;text-decoration:underline;}//对鼠标放到超链接上文字颜色样式变为color:#CC3300;并文字链接加下划线text-decoration:underline;</p><p>copyright www.divcss5.com divcss5</p><p>2、通过链接内设置类控制超链接样式css方法<br />案例超链接代码&lt;a href=&quot;http://www.divcss5.com/&quot; class=&quot;yangshi&quot;&gt;CSS&lt;/a&gt;<br />对应CSS代码<br />a.yangshi{color:#333;text-decoration:none; }<br />a.yangshi:hover {color:#CC3300;text-decoration:underline;}<br />通过这样的设置可以控制链接内的css类名为&ldquo;yangshi&rdquo;超链接的样式 <br />3、通过对应超链接外的父级的css类的css样式来控制超链接的样式<br />案例超链接代码&lt;div class=&quot;yangshi&quot;&gt;&lt;a href=&quot;http://www.divcss5.com/&quot;&gt;CSS&lt;/a&gt;&lt;/a&gt;<br />对应CSS代码<br />.yangshi a{color:#333;text-decoration:none; }<br />.yangshi a:hover {color:#CC3300;text-decoration:underline;} copyright www.divcss5.com divcss5</p><p>这里值得注意的是a.yangshi与.yangshi a的样式css代码区别</p><p>&nbsp;</p><p>这里就是常见的通过div css来对超链接样式设置案例及分析。 <br />&nbsp;</p>]]></description><category>学习笔记</category><comments>http://www.yonghui.net/post/8.html#comment</comments><wfw:comment>http://www.yonghui.net/</wfw:comment><wfw:commentRss>http://www.yonghui.net/feed.asp?cmt=8</wfw:commentRss><trackback:ping>http://www.yonghui.net/cmd.asp?act=tb&amp;id=8&amp;key=e311a2ac</trackback:ping></item><item><title>还是天边那一抹红</title><author>a@b.com (yonghui)</author><link>http://www.yonghui.net/post/6.html</link><pubDate>Sun, 11 Jul 2010 23:30:32 +0800</pubDate><guid>http://www.yonghui.net/post/6.html</guid><description><![CDATA[<p>安康越来越美了，汉江的晚霞也越来越美了，每天游泳完毕，遇到好的天气，拍摄汉江晚景也就成了每天的必修课。</p><p>&nbsp;</p><p><img title="" alt="" src="http://www.yonghui.net/plugin/windsphoto/photofile/20107/201071123328111.jpg" onload="ResizeImage(this,520)" /></p><p>&nbsp;</p><p><img title="" alt="" src="http://www.yonghui.net/plugin/windsphoto/photofile/20107/2010711233224156.jpg" onload="ResizeImage(this,520)" /></p><p>&nbsp;</p><p>&nbsp;</p><p><img title="" alt="" src="http://www.yonghui.net/plugin/windsphoto/photofile/20107/201071123339172.jpg" onload="ResizeImage(this,520)" /></p><p>&nbsp;</p><p>&nbsp;</p><p><img title="" alt="" src="http://www.yonghui.net/plugin/windsphoto/photofile/20107/2010711233327139.jpg" onload="ResizeImage(this,520)" /></p><p>&nbsp;</p><p>&nbsp;</p><p><img title="" alt="" src="http://www.yonghui.net/plugin/windsphoto/photofile/20107/2010711233346186.jpg" onload="ResizeImage(this,520)" /></p><p><img title="" alt="" src="http://www.yonghui.net/plugin/windsphoto/photofile/20107/201071123345125.jpg" onload="ResizeImage(this,520)" /></p><p>&nbsp;</p><p>今天，就在今天，2010年7月11日，我第一次在安康看到了彩虹，记得上次见还是在老家，还是很小的时候。</p><p>&nbsp;</p><p>&nbsp;</p><p><img title="" alt="" src="http://www.yonghui.net/plugin/windsphoto/photofile/20107/2010711233520109.jpg" onload="ResizeImage(this,520)" /></p>]]></description><category>生活日记</category><comments>http://www.yonghui.net/post/6.html#comment</comments><wfw:comment>http://www.yonghui.net/</wfw:comment><wfw:commentRss>http://www.yonghui.net/feed.asp?cmt=6</wfw:commentRss><trackback:ping>http://www.yonghui.net/cmd.asp?act=tb&amp;id=6&amp;key=5b538509</trackback:ping></item><item><title>端午赛龙舟</title><author>a@b.com (yonghui)</author><link>http://www.yonghui.net/post/5.html</link><pubDate>Tue, 15 Jun 2010 15:10:08 +0800</pubDate><guid>http://www.yonghui.net/post/5.html</guid><description><![CDATA[<p>&nbsp;</p><p>　　第十届中国安康汉江龙舟节就要开幕了，今年洽逢安康龙舟节与安康撤地设市十周年之际，龙舟节的规模和档次都属历年之最，五月的汉江是一年最美的季节，趁着龙舟节还没有正式开幕，偷偷溜到船上随拍了几张ＰＰ，以作纪念。</p><p><img title="" alt="" src="http://www.yonghui.net/plugin/windsphoto/photofile/20106/2010615151047179.jpg" onload="ResizeImage(this,520)" /></p><p>&nbsp;</p><p><img title="" alt="" src="http://www.yonghui.net/plugin/windsphoto/photofile/20106/201061515114113.jpg" onload="ResizeImage(this,520)" /></p><p><embed mediatype="3" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" src="http://player.youku.com/player.php/sid/XMTgxNzQ3NDYw/v.swf" width="640" height="480" autostart="true" loop="true" menu="true"></embed></p><p><embed mediatype="3" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" src="http://player.youku.com/player.php/sid/XMTgxNzQ1Mjg4/v.swf" width="640" height="480" autostart="true" loop="true" menu="true"></embed></p>]]></description><category>生活日记</category><comments>http://www.yonghui.net/post/5.html#comment</comments><wfw:comment>http://www.yonghui.net/</wfw:comment><wfw:commentRss>http://www.yonghui.net/feed.asp?cmt=5</wfw:commentRss><trackback:ping>http://www.yonghui.net/cmd.asp?act=tb&amp;id=5&amp;key=f15dbe72</trackback:ping></item><item><title>老汉今年六十八 名字叫做夏绍华</title><author>a@b.com (yonghui)</author><link>http://www.yonghui.net/post/4.html</link><pubDate>Mon, 07 Jun 2010 00:25:56 +0800</pubDate><guid>http://www.yonghui.net/post/4.html</guid><description><![CDATA[<p>　　白河县中厂镇胜利材坎子瀑布，住着这样一位老人，精神矍铄，性格开朗，放弃城里的楼房，自愿住在交通不便的景区门口，看管守护着这一片山林。</p><p style="text-align: center"><br /><embed menu="true" mediatype="3" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" src="http://player.youku.com/player.php/sid/XMTc5MDc1NTMy/v.swf" autostart="true" loop="true" width="480" height="297"></embed></p><p style="text-align: left">&nbsp;</p><p>&nbsp;</p><p><img title="" alt="" onload="ResizeImage(this,520)" src="http://www.yonghui.net/upload/2010/6/201006090029124824.jpg" /></p><p>&nbsp;</p><p><img title="" alt="" onload="ResizeImage(this,520)" src="http://www.yonghui.net/upload/2010/6/201006090030060217.jpg" /></p><p>&nbsp;</p><p><img title="" alt="" onload="ResizeImage(this,520)" src="http://www.yonghui.net/upload/2010/6/201006090030446231.jpg" /></p><p>&nbsp;</p><p><img title="" alt="" onload="ResizeImage(this,520)" src="http://www.yonghui.net/upload/2010/6/201006090031228031.jpg" /></p>]]></description><category>摄影</category><comments>http://www.yonghui.net/post/4.html#comment</comments><wfw:comment>http://www.yonghui.net/</wfw:comment><wfw:commentRss>http://www.yonghui.net/feed.asp?cmt=4</wfw:commentRss><trackback:ping>http://www.yonghui.net/cmd.asp?act=tb&amp;id=4&amp;key=8e7962f3</trackback:ping></item><item><title>又是一年五月时</title><author>a@b.com (yonghui)</author><link>http://www.yonghui.net/post/3.html</link><pubDate>Sat, 08 May 2010 23:35:27 +0800</pubDate><guid>http://www.yonghui.net/post/3.html</guid><description><![CDATA[<p>&nbsp;</p><p><img title="" alt="" onload="ResizeImage(this,520)" src="http://www.yonghui.net/upload/2010/6/r1.jpg" /></p><p><span style="font-size: medium">&nbsp;　　过的真快啊，彭彭，马上就要迎来４岁的生日了，你的每一个生日，爸爸和妈妈也陪着你成长了一岁。你是爸爸妈妈最疼爱的人，倾注了爸爸妈妈所有的心血。未来的日子，也许不会一帆风顺，会经历很多磨难，因为一帆风顺的人生是悲哀的，爸爸希望你学会坚强， 勇敢的面对一切。</span></p><p><img title="" alt="" onload="ResizeImage(this,520)" src="http://www.yonghui.net/upload/2010/6/201006082359532643.jpg" /></p>]]></description><category>生活日记</category><comments>http://www.yonghui.net/post/3.html#comment</comments><wfw:comment>http://www.yonghui.net/</wfw:comment><wfw:commentRss>http://www.yonghui.net/feed.asp?cmt=3</wfw:commentRss><trackback:ping>http://www.yonghui.net/cmd.asp?act=tb&amp;id=3&amp;key=50e7b9df</trackback:ping></item><item><title>发一组儿子的照片</title><author>a@b.com (yonghui)</author><link>http://www.yonghui.net/post/2.html</link><pubDate>Thu, 28 Jan 2010 15:02:56 +0800</pubDate><guid>http://www.yonghui.net/post/2.html</guid><description><![CDATA[<p>&nbsp;宝贝三岁生日的一组照片，愿你健健康康、快快乐乐、平平安康。</p><p>&nbsp;<img title="" alt="" onload="ResizeImage(this,520)" src="http://www.yonghui.net/upload/2010/1/2q.jpg" /></p><p><img title="" alt="" onload="ResizeImage(this,520)" src="http://www.yonghui.net/upload/2010/1/4.jpg" /></p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p><img title="" alt="" onload="ResizeImage(this,520)" src="http://www.yonghui.net/upload/2010/1/1q.jpg" /></p><p>&nbsp;</p><p>&nbsp;</p><p><img title="" alt="" onload="ResizeImage(this,520)" src="http://www.yonghui.net/upload/2010/1/090510211818240e9045ac1c9a.jpg" /></p>]]></description><category>生活日记</category><comments>http://www.yonghui.net/post/2.html#comment</comments><wfw:comment>http://www.yonghui.net/</wfw:comment><wfw:commentRss>http://www.yonghui.net/feed.asp?cmt=2</wfw:commentRss><trackback:ping>http://www.yonghui.net/cmd.asp?act=tb&amp;id=2&amp;key=97cd596a</trackback:ping></item><item><title>终于再次打开yonghui.net</title><author>a@b.com (yonghui)</author><link>http://www.yonghui.net/post/1.html</link><pubDate>Wed, 27 Jan 2010 21:16:34 +0800</pubDate><guid>http://www.yonghui.net/post/1.html</guid><description><![CDATA[<p>　　算一算接触互联网已经十几个年头了，从事这个工作也已经整整十年了，2002年3月，自己用自己的名字注册了yonghui.net，建立自己的个人网站，其实这不是我第一次建个人网站了，我从1999年就开始建个人网站，申请网易的免费个人空间，那时候的网站名称&ldquo;永辉视线&rdquo;，可是自己一直不能坚持，没有做起来，呵呵，懒惰哦~~。注册域名后，也做过很多版式，但都没有坚持多久，这次又再次开通yonghui.net，希望能够坚持下来，记录生活点滴，记录学习笔记，希望我的朋友们共同来监督我。</p><p>　　<img alt="" src="http://www.yonghui.net/image/face/Effort.gif" /><img alt="" src="http://www.yonghui.net/image/face/Hehe.gif" /></p>]]></description><category>生活日记</category><comments>http://www.yonghui.net/post/1.html#comment</comments><wfw:comment>http://www.yonghui.net/</wfw:comment><wfw:commentRss>http://www.yonghui.net/feed.asp?cmt=1</wfw:commentRss><trackback:ping>http://www.yonghui.net/cmd.asp?act=tb&amp;id=1&amp;key=b30c006e</trackback:ping></item></channel></rss>

