PHPÐÂÊÖÉÏ·£¨¾Å£©

5年以前  |  阅读数:839 次  |  编程语言:PHP 

½¨ÉeÒ»¸o¼oµ¥½»»¥µÄÍøÕ¾(Îa)

8. ͶƱϵͳ

¡¡¡¡ÔÚÐi¶aʱºo£¬ÎÒÃÇÐeÒªÊÕ¼¯ÉÏÍøÕߺÍÍøÓÑÃǵÄÒa¼u¡£ÀýÈ磺аaeÒ³ÃaeÓe¾É°aeÒ³ÃaeµÄ±È½Ï£»¶ÔijһÊÂÇeµÄ¿´¨£»¶ÔÌaÓý±ÈÈu½a¹uµÄÔ¤²aµÈµÈ¡£Õaʱºo£¬ÄaÐeÒªÒ»¸odz£ÓÐЧµÄÍøÉϵ÷²eϵͳ¡£Ê¹ÓÃPHP¾Í¿ÉÒÔdz£½±aµØʵÏÖÄaµÄÕaÒ»¹¹Ïe¡£

8.1 ͶƱϵͳ£¨mypolls.php3£(C)£º

<?
$status=0;
if(isset($polled)&&($polled=="c-e")){
$status=1;
}

echo "$status";

if(isset($poll)&&($status==0)){
setcookie("polled","c-e",time()+86400,"/");#time=24h
}
?>

аaeÒ³Ãaeµ÷²e
Óe¾É°aeÒ³ÃaeÏa±È½ÏÄu¾oµÃаaeÒ³Ãae£º

ÐÅÏ¢Á¿¸u´o
ÍøÒ³¸u¾«ÃÀ
ûʲô¸Ä½ø
ÆaËu
²e¿´µ÷²e½a¹u
"ÐÅÏ¢Á¿¸u´o", 2=>"ÍøÒ³¸u¾«ÃÀ", 3=>"ûʲô¸Ä½ø", 4=>"ÆaËu" ); $poll_resultBarHeight = 9; // height in pixels of percentage bar in result table $poll_resultBarScale = 1; // scale of result bar (in multiples of 100 pixels) $poll_tableHeader=""; $poll_rowHeader=""; $poll_dataHeader=""; $poll_rowFooter=""; $poll_tableFooter="
"; $poll_dataFooter="
"; $coutfile="data.pol"; $poll_sum=0;

// read counter-file
if (file_exists( $coutfile))
{
$fp = fopen( $coutfile, "rt");
while ($Line = fgets($fp, 10))
{
// split lines into identifier/counter
if (ereg( "([^ ]) ([0-9]*)", $Line, $tmp))
{
$curArray[(int)$tmp[1]] = (int)$tmp[2];
$poll_sum+=(int)$tmp[2];
}
}
// close file
fclose($fp);
}else{//
for ($i=1;$i<=count($descArray);$i++){
$curArray[$i]=0;
}
}
if(isset($poll)){
$curArray[$poll_voteNr]++;
$poll_sum++;
}
echo $poll_tableHeader;

// cycle through all options±aÀuÊý×e
reset($curArray);
while (list($K, $V) = each($curArray))
{
$poll_optionText = $descArray[$K];
$poll_optionCount = $V;
echo $poll_rowHeader;

if($poll_optionText != "")
{
echo $poll_dataHeader;
echo $poll_optionText;
echo $poll_dataFooter;

if($poll_sum)
$poll_percent = 100 * $poll_optionCount / $poll_sum;
else
$poll_percent = 0;
echo $poll_dataHeader;

if ($poll_percent > 0)
{
$poll_percentScale = (int)($poll_percent * $poll_resultBarScale);
}

printf(" %.2f %% (%d)", $poll_percent, $poll_optionCount);

echo $poll_dataFooter;
}

echo $poll_rowFooter;
}

echo "×ܹ²Í¶Æ±´ÎÊý: $poll_sum";
echo $poll_tableFooter;
echo "
";
echo "";
echo " ";
if(isset($poll)){
// write counter file
$fp = fopen($coutfile, "wt");
reset($curArray);
while (list($Key, $Value) = each($curArray))
{
$tmp = sprintf( "%s %dn", $Key, $Value);
fwrite($fp, $tmp);
}
// close file
fclose($fp);
}
}
?>

×¢ÊÍ£º´ÓÉÏÃaeÎÒÃÇ¿ÉÒÔ¿´³o¸ÃͶƱϵͳµÄ»u±¾¹ý³Ì£º
1¡¢´o¿ªÎļþÈ¡µÃÊý¾Ýµ½Êý×e$curArray£¨Îļþ²»´aeÔÚÔo³oʼ»¯Êý×e$curArray£(C)
2¡¢±aÀuÊý×e£¬´¦ÀiÊý¾ÝµÃµ½ËuÐeÖµ
3¡¢¼ÆËa°Ù*ֱȣ¬¿ØÖÆͳ¼ÆbarͼÏñ¿i¶È
4¡¢½«Êý¾Ý±£´aeµ½"data.pol"ÖÐ

¡¡¡¡ ÕaÀiÓÐÒ»µaÊÇÐeҪעÒa£ºÕaÀiµÄdata.polÎı¾ÎļþÐeÒªÓÐдȨÏÞ¡£

 相关文章:
PHP分页显示制作详细讲解
SSH 登录失败:Host key verification failed
获取IMSI
将二进制数据转为16进制以便显示
获取IMEI
文件下载
贪吃蛇
双位运算符
PHP自定义函数获取搜索引擎来源关键字的方法
Java生成UUID
发送邮件
年的日历图
提取后缀名
在Zeus Web Server中安装PHP语言支持
让你成为最历害的git提交人
Yii2汉字转拼音类的实例代码
再谈PHP中单双引号的区别详解
指定应用ID以获取对应的应用名称
Python 2与Python 3版本和编码的对比
php封装的page分页类完整实例