首页 > phper

php strstr() strrchr() strpos() strrpos()函数

<?php
//strstr:从左向右查找  返回值:字符串
//strrchr:从右向左查找 返回值:字符串
//strpos:从左向右查找  返回值:整型,假如查找的字符串不存在,则返回空
//strrpos:从右向左查找 返回值:整型
$str="天高任鸟飞,海阔凭鱼跃";//strstr:从左向右查找  strrchr:从右向左查找
echo "原始字符串:".$str."<br />";
echo "用strstr函数搜索“,”的返回结果:".strstr($str,",")."<br>";
echo "用strstr函数搜索“鸟飞”的返回结果:".strstr($str,"鸟飞")."<br>";

阅读全文

php下导入.sql到数据库的方法

以前我们都是利用phpmyadmin或在dos下进行.sql文件的导入,今天我们来看看在php下同样可以实现把.sql文件导入到mysql数据库中哦。  代码如下 复制代码 <?php$conn=mysql_connect(“localhost”,”root”,”password”);//指定数据库连接参数function mysql_import($file,$database)// 导入的函数,参数为SQL文件路径和导入的库名。{mysql_sele...
阅读全文

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代码

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

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货币换算程序代码哦,有需要的朋友可以参考一下。

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 ($).

阅读全文