php检测邮箱地址是否存在
在php中有这么一个函数checkdnsrr来验证dns是否可访问来检测邮箱地址是否存在
*/
代码如下 | 复制代码 |
$email ="abc@111cn.net"; if($check_email) { return true; } else { return false; } |
/*
关于checkdnsrr函数详细说明
bool checkdnsrr ( string $host [, string $type = "mx" ] )
checkdnsrr. 检查指定网址的dns 记录
<?php
代码如下 | 复制代码 |
//this will not work //but every value other than "any" will work |
指定的参数 host 可以是网络位址 (ip address),也可以用机器名称 (domain name)。参数 type 可以省略,内定值为 mx。而参数 type 的值可为以下的其中之一:a、mx、ns、soa、ptr、cname 或 any。若找到了指定网址的 dns 字段,返回 true;若未找到指定的 dns 字段或是有错误均会返回 false。
本文章主要讲到两种php 字符串替换函数 str_replace与substr_replace前一种是替换所有haystace中的needle,并返回haystace替换后的结果,而substr_replace替换字符串string中的一部分具体哪能一部分则取决于起始位置和可选参数length的值
最常用str_replace()
函数原型:
mixed str_replace(mixed needle,mixed new_needle,mixed haystace[,int &count])
函数用new_needle替换所有haystace中的needle,并返回haystace替换后的结果.可选的第四个参数count,它包含要执行的替换操作次数.
例:
代码如下 | 复制代码 |
<?php function n2n() { =array('1','2','3','4','5','6','7','8','9','0'); =array("7","8","9","0","1","2","3","4","5","6"); =strlen(); for(=0;<;++){ for(=0;<10;++) if(==){ = str_replace(, , ); break; } } return ; } ="1234abc56"; echo n2n(); ?> |
函数substr_replace()则用来在给定位置中查找和替换字符串中特定的子字符串.原型:
string substr_replace(string string,string replacement,int start,int[length]);
代码如下 | 复制代码 |
<?php echo substr_replace("hello world","earth",6);//hello earth ?> |
负数时
代码如下 | 复制代码 |
<?php substr_replace('huevos','x',-2,-2); //huevxos substr_replace('huevos','x',-2,-3); //huevxos substr_replace('huevos','x',-2,-3); //huevxos ?> |
函数使用字符串replacement替换字符串string中的一部分具体哪能一部分则取决于起始位置和可选参数length的值.
start的值代表要替换字符串位置的开始偏移量.如果它为0或是一个正值,就是一个从字符串开始处计算的偏移量;如果它是一个负值,就是从字
浏览器关闭的过程中,服务器上的 session 数据并没有被销毁,因为这时候没有发送任何请求,服务器那边不会知道是否要销毁 session 的数据。浏览器再次启动重新打开页面的时候,发送的 session id 还是原来的 id,虽然你说没用到 cookie,但是这个 id 就是通过 cookie 发送的。
你可以看看 php.ini 的设置,主要看这两项:
代码如下 | 复制代码 |
session.gc_maxlifetime session.cookie_lifetime |
方法二利用onload函数
代码如下 | 复制代码 |
<body onunload="ajax()"> |
主要是购物车部分代码的讲解,和对session操作的php教程代码演示。
<?php
//
// add_item.php:
// add an item to the shopping cart.
//
session_start();
if (session_is_registered('cart')) {
session_register('cart');
}require 'lib.inc.php'; // loadproducts()
loadproducts(); // load products in $master_products_list
// make $curr_product global
$curr_product = array();// loop through all the products and pull up the product
// that we are interested in
foreach ($master_products_list as $prod_id => $product) {
if (trim($prod_id) == trim($_get[id])) {
$curr_product = $product;
}
}
// register our session
//session_register('cart');
//if(session_is_registered('cart')) echo "已经注册";
if ($_post[ordered]) { // if they have chosen the product
array_push($_session[cart][products], array(trim($_post[id]), $_post[quantity]));
$_session[cart][num_items] += $_post[quantity];
}
?><html>
<head>
<title>
<?php if ($_post[ordered]) { ?>
已经添加 <?php echo $curr_product[name]; ?> 到您的购物篮
<?php } else { ?>
添加 <?php echo $curr_product[name]; ?> 到您的购物篮
<?php } ?>
</title>
</head>
<body>
<?php if ($_post[ordered]) { ?>
<h1><?php echo $curr_product[name]; ?>
添加至购物篮成功</h1><a href="cart.php">返回</a> 商品列表页面.
<?php } else { ?>
<h1>添加 <?php echo $curr_product[name]; ?> 到您的购物篮</h1><form action="<?php echo $php_self; ?>" method="post">
商品名称: <?php echo $curr_product[name]; ?>
<br>
商品说明: <?php echo $curr_product[desc]; ?>
<br>
商品单价: rmb<?php echo $curr_product[price]; ?>
<br>
商品数量: <input type="text" size="7" name="quantity">
<input type="hidden" name="id" value="<?php echo $_get[id]; ?>">
<input type="hidden" name="ordered" value="1"><input type="submit" value="添加至购物栏">
</form>
<?php } ?>
</body>
</html>
php代码
<?php
//
// cart.php: the main file
//
session_start();require 'lib.inc.php';
//判断购物篮会话变量cart是否注册,不注册则注册cart变量
if (session_is_registered('cart')) {
session_register('cart');
}
// 如果购物篮没有初始化,则初始化购物篮
if (!isset($_session[cart][num_items])) {
$_session[cart] = array("num_items" => 0,
"products" => array());
}
// from site_lib.inc, loads the $master_products_list array
loadproducts(); //载入物品列表
?><html>
<head>
<title>演示会话跟踪的购物篮程序</title>
</head><body>
<h1>欢迎进入网上商店</h1>
<?php
if ($_session[cart][num_items]) { // if there is something to show
?>
<h2>当前在购物篮里的物品</h2>
<br>
<table border="2" cellpadding="5" cellspacing="2">
<tr>
<th>
商品名称
</th>
<th>
商品说明
</th>
<th>
单价
</th>
<th>
数量
</th>
<th>
</th>
</tr>
<?php
// loop through the products
foreach ($_session[cart][products] as $i => $product) {
$product_id = $product[0];
$quantity = $product[1];$total += $quantity *
(double)$master_products_list[$product_id][price];
?>
<tr>
<td>
<?php echo $master_products_list[$product_id][name]; ?>
</td>
<td>
<?php echo $master_products_list[$product_id][desc]; ?>
</td>
<td>
<?php echo $master_products_list[$product_id][price]; ?>
</td>
<td>
<form action="change_quant.php" method="post">
<input type="hidden" name="id" value="<?php echo $i; ?>">
<input type="text" size="3" name="quantity"
value="<?php echo $quantity; ?>">
</td>
<td>
<input type="submit" value="数量更改">
</form>
</td>
</tr>
<?php
}
?>
<tr>
<td colspan="2" align="right">
<b>合计: </b>
</td>
<td colspan="2">
rmb:<?php echo $total; ?>
</td>
<td> </td>
</tr>
</table>
<br>
<br>
<?php
}
?><h2>商店待出售的商品</h2>
<br>
<i>
我们提供以下商品待售:
</i>
<br>
<table border="2" cellpadding="5" cellspacing="2">
<tr>
<th>
商品名称
</th>
<th>
商品说明
</th>
<th>
单价
</th>
<th>
</th>
</tr>
<?php
// show all of the products
foreach ($master_products_list as $product_id => $item) {
?>
<tr>
<td>
<?php echo $item[name]; ?>
</td>
<td>
<?php echo $item[desc]; ?>
</td>
<td>
$<?php echo $item[price]; ?>
</td>
<td>
<a href="add_item.php?id=<?php echo $product_id; ?>">
添加至购物篮
</a>
</td>
</tr>
<?php
}?>
</table>
购物车
<?php
//
// change_quant.php:
// change the quantity of an item in the shopping cart.
//
session_start();
if (session_is_registered('cart')) {
session_register('cart');
}// typecast to int, making sure we access the
// right element below
$i = (int)$_post[id];// save the old number of products for display
// and arithmetic
$old_num = $_session[cart][products][$i][1];if ($_post[quantity]) {
$_session[cart][products][$i][1] = $_post[quantity]; //change the quantity
} else {
unset($_session[cart][products][$i]); // send the product into oblivion
}// update the number of items
$_session[cart][num_items] = ($old_num >$_post[quantity]) ?
$_session[cart][num_items] - ($old_num-$_post[quantity]) :
$_session[cart][num_items] + ($_post[quantity]-$old_num);
?><html>
<head>
<title>
数量修改
</title>
</head>
<body>
<h1> 将数量: <?php echo $old_num; ?> 更改为
<?php echo $_post[quantity]; ?></h1>
<a href="cart.php">返回</a> 商品列表页面.
</body>
</html>
打开文件
<?php
//物品数组
$master_products_list = array();
//载入物品数据函数
function loadproducts() {
global $master_products_list;
$filename = 'products.txt';$fp = @fopen($filename, "r")
or die("打开 $filename 文件失败");
@flock($fp, 1)
or die("锁定 $filename 文件失败");//读取文件内容
while ($line = fgets($fp, 1024)) {
list($id, $name, $desc, $price) = explode('|', $line); //读取每行数据,数据以| 格开
$id = trim($id); //去掉首尾特殊符号
$master_products_list[$id] = array("name" => $name, //名称
"desc" => $desc, //说明
"price" => $price); //单价
}@fclose($fp) //关闭文件
or die("关闭 $filename 文件失败");
}
?>
本文章利用用大量的例子来讲解php教程代码对图片操作的讲解。下面来看看一个个实例教程吧.
<?php
$height = 300;
$width = 300;
//创建背景图
$im = imagecreatetruecolor($width, $height);
//分配颜色
$white = imagecolorallocate ($im, 255, 255, 255);
$blue = imagecolorallocate ($im, 0, 0, 64);
//绘制颜色至图像中
imagefill($im, 0, 0, $blue);
//绘制字符串:hello,php
imagestring($im, 10, 100, 120, 'hello,php', $white);
//输出图像,定义头
header ('content-type: image/png');
//将图像发送至浏览器
imagepng($im);
//清除资源
imagedestroy($im);
?>
实例二生成缩略图片
<?php
header("content-type: image/jpeg");
// 载入图像
$imagen1 = imagecreatefromjpeg("imagen1.jpg");
$imagen2 = imagecreatefromjpeg("imagen2.jpg");// 复制图像
imagecopy($imagen1,$imagen2,0,0,0,0,200,150);// 输出jpeg图像
imagejpeg($imagen1);//释放内存
imagedestroy($imagen2);
imagedestroy($imagen1);?>
获取图片大小信息
<?php
$info = getimagesize("imagen2.jpg");
print_r($info);?>
绘制png图片
<?php
//png格式图像处理函数
function loadpng ($imgname) {
$im = @imagecreatefrompng ($imgname);
if (!$im) { //载入图像失败
$im = imagecreate (400, 30);
$bgc = imagecolorallocate ($im, 255, 255, 255);
$tc = imagecolorallocate ($im, 0, 0, 0);
imagefilledrectangle ($im, 0, 0, 150, 30, $bgc);
imagestring($im, 4, 5, 5, "error loading: $imgname", $tc);
}
return $im;
}
$imgpng=loadpng("./karte.png");
/* 输出图像到浏览器 */
header("content-type: image/png");
imagepng($imgpng);
?>
给图片加文字
<?php
//创建 100*30 图像
$im = imagecreate(100, 30);
// white background and blue text
$bg = imagecolorallocate($im, 200, 200, 200);
$textcolor = imagecolorallocate($im, 0, 0, 255);
// write the string at the top left
imagestring($im, 5, 0, 0, "hello world!", $textcolor);
// output the image
header ("content-type: image/jpeg");
imagejpeg ($im);
imagedestroy($im);?>
相关文章
- 对于游戏中出现的每一样东西,比如砖块箱子水管地面,还有人物都可以看成是一个独立的物体,所以每个物体类都继承了pygame的精灵类pg.sprite.Sprite,这篇文章主要给大家介绍了关于Python Pygame中精灵和碰撞检测的相关资料,需要的朋友可以参考下...2021-10-05
- 这篇文章主要给大家介绍了关于如何检测JavaScript中死循环的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-08-31
- 这篇文章主要介绍了python基于opencv检测程序运行效率,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下...2020-05-09
- 这篇文章主要介绍了iOS WKWebview 白屏检测实现的示例,帮助大家更好的进行ios开发,感兴趣的朋友可以了解下...2020-10-20
- 这篇文章主要介绍了php判断邮箱地址是否存在的方法,php判断邮箱地址是否存在的方法有两种,感兴趣的朋友可以参考一下...2016-02-18
- 这篇文章主要介绍了c# 判断指定文件是否存在的简单实现,需要的朋友可以参考下...2020-06-25
- 一篇php中匹配邮箱地址正则表达式实例,邮箱地址替换正则我常用的正则匹配表达式:/^[a-z]([a-z0-9]*[-_]?[a-z0-9]+)*@([a-z0-9]*[-_]?[a-z0-9]+)+[\\.][a-z]{2,3}([\\....2016-11-25
- 这篇文章主要为大家详细介绍了OpenCV实现图像轮廓检测以及外接矩形,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2020-04-25
- 本文主要介绍了OpenCV实现低对比度图像脏污区域检测,文中通过示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2021-09-29
- VC判断进程是否存在?比如我想知道记事本是否运行,要用到哪些函数等实例,需要的朋友可以参考下...2020-04-25
- 这篇文章主要为大家详细介绍了OpenCV实现图像角点检测,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2020-04-25
- 这篇文章主要介绍了C++检查某个文件或目录是否存在的函数,是Windows应用程序设计中非常常见的实用技巧,需要的朋友可以参考下...2020-04-25
- 个人觉得邮箱正则表达式在javascript与php中一样的规则了,只是语法稍有不同,下面我就把在服务器与客户端邮箱验证代码给大家看看。 邮箱地址验证有很多方法。在浏...2016-11-25
- phpMyAdmin ( http://www.phpwizard.net/projects/phpMyAdmin/ ) 是一款管理 MySQL 数据库的 PHP 工具,具有基于 WEB 的界面。但是发现它存在漏洞。可选择安装新发布稳...2016-11-25
- 这篇文章主要介绍了Python实现定时监测网站状态的示例代码,帮助大家更好的管理自己的网站,感兴趣的朋友可以了解下...2020-10-01
python opencv实现直线检测并测出倾斜角度(附源码+注释)
这篇文章主要介绍了python opencv实现直线检测并测出倾斜角度(附源码+注释),文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-12-31- 这篇文章主要介绍了C++ 网络连通性检测的实现方法的相关资料,这里提供实例帮助大家实现这样的功能,需要的朋友可以参考下...2020-04-25
- 能够检测大部分通过代理服务器访问的ip. <?php //beiji.com 2000.6.17 $ip = getenv("REMOTE_ADDR"); $v = getenv("HTTP_VIA"); $f = getenv("HTTP_X_FORWARDED...2016-11-25
BBSMAX发布部署提示”default.aspx”中模版变量”PageTitle”不存在,请检查模版
下面我们一起来看看关于BBSMAX发布部署提示”default.aspx”中模版变量”PageTitle”不存在,请检查模版解决办法。 今又想起了bbsmax,拿出来试验测试下!翻出了bbsmax...2016-11-25- 这篇文章主要为大家详细介绍了C++利用opencv实现人脸检测,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2020-04-25