当前位置: 编程技术>php
本页文章导读:
▪php 扑克牌代码的简单例子 php 扑克牌代码,如下:
<?php
/***
*
* A simple class to cut a deck of cards
* @version CVS: $Id:$
* @since Class available since Release 1.0.0
* Example use
*
* $cards = new cards;
* echo $cards->cut();
* www:
*/.........
▪php 云标签的实现代码 在如今的php网站中,云标签的大量应用,使页面显得生效而有趣,也增加了相关内容的索引与检索。
本节分享一段php 云标签的实现代码,有兴趣的朋友,可以研究下。
1,css代码部分
<sty.........
▪php 匹配apache日志日期的代码 以下代码可用于匹配apache日志中的日期,然后得到类似:17 Dec 06 03:26:49 -0500的返回结果。
php得到apache日志中的日期,如下:
<?php
// Set the default timezone to US/Eastern time:
date_default_timezone_set('.........
[1]php 扑克牌代码的简单例子
来源: 互联网 发布时间: 2013-12-24
php 扑克牌代码,如下:
<?php /*** * * A simple class to cut a deck of cards * @version CVS: $Id:$ * @since Class available since Release 1.0.0 * Example use * * $cards = new cards; * echo $cards->cut(); * www: */ class cards{ /** * * Declare our deck variable * */ private $deck; /** * * Constructor.. duh! * */ function __construct(){ /*** set the deck array variable ***/ $this->deck=$this->setDeck(); } /** * * Function set Deck * * @access private * * @return array * */ private function setDeck(){ return array("ah", "ac", "ad", "as", "2h", "2c", "2d", "2s", "3h", "3c", "3d", "3s", "4h", "4c", "4d", "4s", "5h", "5c", "5d", "5s", "6h", "6c", "6d", "6s", "7h", "7c", "7d", "7s", "8h", "8c", "8d", "8s", "9h", "9c", "9d", "9s", "th", "tc", "td", "ts", "jh", "jc", "jd", "js", "qh", "qc", "qd", "qs", "kh", "kc", "kd", "ks"); } /** * * Function get Key get the array key * * @access private * * @return INT * */ private function getKey(){ shuffle($this->deck); return array_rand($this->deck); } /** * * @Function cut, get the value of the array key * * @access public * * @return string * */ public function cut(){ return $this->deck[$this->getKey()]; } } /*** end of class ***/ $cards = new cards; echo $cards->cut(); ?>
[2]php 云标签的实现代码
来源: 互联网 发布时间: 2013-12-24
在如今的php网站中,云标签的大量应用,使页面显得生效而有趣,也增加了相关内容的索引与检索。
本节分享一段php 云标签的实现代码,有兴趣的朋友,可以研究下。
1,css代码部分
<style type="text/css"> #tagcloud{ color: #dda0dd; font-family: Arial, verdana, sans-serif; width:200px; border: 1px solid black; text-align: center; } #tagcloud a{ color: green; text-decoration: none; text-transform: capitalize; } </style>
2,php 云标签的展示部分
<div id="tagcloud"> <?php /** this is our array of tags * We feed this array of tags and links the tagCloud * class method createTagCloud */ $tags = array( array('weight' =>40, 'tagname' =>'tutorials', 'url'=>'http://www./tutorials/'), array('weight' =>12, 'tagname' =>'examples', 'url'=>'http://www./examples/'), array('weight' =>10, 'tagname' =>'contact', 'url'=>'http://www./contact/'), array('weight' =>15, 'tagname' =>'quotes', 'url'=>'http://www./quotes/'), array('weight' =>28, 'tagname' =>'devel', 'url'=>'http://www./phpdev/'), array('weight' =>35, 'tagname' =>'manual', 'url'=>'http://www./en/index.html'), array('weight' =>20, 'tagname' =>'articles', 'url'=>'http://www./articles/'), ); /*** create a new tag cloud object ***/ $tagCloud = new tagCloud($tags); echo $tagCloud -> displayTagCloud(); ?> </div> </body> </html> <?php /** * php 云标签类 * by www. */ class tagCloud{ /*** the array of tags ***/ private $tagsArray; public function __construct($tags){ /*** set a few properties ***/ $this->tagsArray = $tags; } /** * * Display tag cloud * * @access public * * @return string * */ public function displayTagCloud(){ $ret = ''; shuffle($this->tagsArray); foreach($this->tagsArray as $tag) { $ret.='<a .$tag['weight'].'px;" href="'.$tag['url'].'">'.$tag['tagname'].'</a>'."\n"; } return $ret; } } /*** end of class ***/ ?>
php 云标签的演示效果,如下图:
[3]php 匹配apache日志日期的代码
来源: 互联网 发布时间: 2013-12-24
以下代码可用于匹配apache日志中的日期,然后得到类似:17 Dec 06 03:26:49 -0500的返回结果。
php得到apache日志中的日期,如下:
<?php // Set the default timezone to US/Eastern time: date_default_timezone_set('US/Eastern'); // Simulate reading an Apache log file, with the following line: $logline = '127.0.0.1 - - [17/dec/2006:00:26:49 -0800] "GET / HTTP/1.1" 200 41228'; // Since we only want the date section, use regex to obtain it: preg_match('/\[(.*?)\]/', $logline, $matches); // Take the date, and convert it: $timestamp = strtotime($matches[1]); // Now echo it out again to ensure that we read it correctly: echo date(DATE_RFC822, $timestamp); ?>
最新技术文章: