首页 > php开发

php四舍五入函数

这里统计了php中大量的四舍五入函数,包括有round(),ceil(),floor()等,有需要的朋友参考一下。  代码如下 复制代码 <?php  $s = rand(100,200);    $pi=pi();  $r=sqrt($s/$pi);  $qz1=round($r);   //四舍五入取整  $qz2=ceil($r);    //进一法取整  $qz3=floor($r);&n...
阅读全文

php 购物车程序

<?php
class Shopcar
{
//商品列表
public  $productList=array();

/**
 *
 * @param unknown_type $product 传进来的商品
 * @return true 购物车里面没有该商品
 */
public function checkProduct($product)
{
 
 for($i=0;$i<count($this->productList);$i++ )
 {
 
  if($this->productList[$i]['name']==$product['name'])  
  return $i;
 }
 
 return -1;

阅读全文

php fsockopen模仿用户post数据

<?php
function wfopen(http://pic3.phprm.com/2011/10/08/$url.jpg,$post='',$cookie='',$timeout=15) {
        $matches = parse_url($url);
        $out = "POST {$matches['path']} HTTP/1.0rn";
        $out .= "Accept: */*rn";
        $out .= "Accept-Language: zh-cnrn";
        $out .= "Content-Type: application/x-www-form-urlencodedrn";
        $out .= "User-Agent: $_SERVER[HTTP_USER_AGENT] rn";
        $out .= "Host: {$matches['host']}rn";
        $out .= 'Content-Length: '.strlen($post)."rn";
        $out .= "Connection: Closern";
        $out .= "Cache-Control: no-cachern";
        $out .= "Cookie: $cookiernrn";
        $out .= $post;
        $socket = @fsockopen($matches['host'],80,$errno,$errstr,$timeout) or die("$errstr($errno)");
        fwrite($socket,$out);
        $header = $data = "";
        while($infos = trim(fgets($socket,4096))) {
                $header.=$infos;
        }
        while(!feof($socket)) {
                $data .= fgets($socket,4096);
        }
        return $data;
}
echo wfopen('http://localhost/te.php','id=5');
?>

阅读全文

把数字转换成汉字的php代码

提供一款大家可能用得比较少的把数字转换成汉字的php代码,有需要的朋友可以参考一下。  代码如下 复制代码 //将数字转换为汉字,比如1210转换为一千二百一十$num = "842105580";//九位数function del0($num) //去掉数字段前面的0{return "".intval($num);}function n2c($x) //单个数字变汉字{$arr_n = array("零","一","二",&quo...
阅读全文

PHP货币换算程序代码

一款实用的PHP货币换算程序代码哦,有需要的朋友可以参考一下。

Copy the above code into a new file and save it as CurrencyConverter.php. Whenever you need to make a conversion just include the class file and call the &lsquo;convert&rsquo; function. You will need to enter your own mysql database variables such as the login details. The example below will convert &pound;2.50 GBP into US Dollars ($).

阅读全文

php cookie登录验证代码

<html>
<head>
<title>Login</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<form name="form1" method="post" action="login.php">
<table width="300" border="0" align="center" cellpadding="2" cellspacing="2">
    <tr>
      <td width="150"><div align="right">用户名:</div></td>
      <td width="150"><input type="text" name="username"></td>
    </tr>
    <tr>
      <td><div align="right">密码:</div></td>
      <td><input type="password" name="passcode"></td>
    </tr>
    <tr>
      <td><div align="right">Cookie保存时间:</div></td>
      <td><select name="cookie" id="cookie">
        <option value="0" selected>浏览器进程</option>
        <option value="1">保存1天</option>
        <option value="2">保存30天</option>
        <option value="3">保存365天</option>
      </select></td>
    </tr>
</table>
<p align="center">
    <input type="submit" name="Submit" value="Submit">
    <input type="reset" name="Reset" value="Reset">
</p>
</form>
</body>
</html>

阅读全文

phpthink中字符串截取代码-支持中文和其它编码

一款不错的支持中文和其它编码截取函数,不会出现乱码情况,有需要的朋友可以参考一下。  代码如下 复制代码 /**+----------------------------------------------------------* 字符串截取,支持中文和其它编码+----------------------------------------------------------* @param string $str 需要转换的字符串* @param string $start 开始位置* @param string $le...
阅读全文

经典php批量上传源码

html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
function Check(){
 //alert('dddd');
 for(i=1; i<9; i++){
  if(document.getElementById('v'+i).value == ''){
   document.getElementById('v'+i).name = 'uu';
  }
 }
}

阅读全文