以前做过一个招聘网站这样我们需要让别有采集不到我们客户的手机号码与邮箱地址了,所以我们会利用php实现从数据库读出来的手机号码与邮箱地址直接生成一张图片了,这样采集过去只能是图片并且无法识别了,下面我来给大家介绍两个实例.
PHP字符串处理-将手机号码生存图片,代码如下:
-
-
-
function str_to_image($str,$w=130,$h=25,$rand=true)
-
{
-
-
Header("Content-type:image/png");
-
-
$nwidth=$w;
-
$nheight=$h;
-
-
$randval=$str;
-
$im=@imagecreate($nwidth,$nheight) or die("Can't initialize new GD image stream");
-
-
$background_color=imagecolorallocate($im,255,255,255);
-
$text_color=imagecolorallocate($im,23,14,91);
-
-
imagefilledrectangle($im,0,0,$nwidth-1,$nheight-1,$background);
-
imagerectangle($im,0,0,$nwidth-1,$nheight-1,$background_color);
-
imagestring($im,8,10,4,$randval,$text_color);
-
if($rand){
-
-
for($i=0;$i<260;$i++)
-
{
-
$randcolor=imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255));
-
imagesetpixel($im,rand()%($nwidth-5),rand()%($nheight+5),$randcolor);
-
}
-
}
-
-
-
imagepng($im);
-
imagedestroy($im);
-
}
-
-
$str = '13087263453';
-
echo str_to_image($str,$w=130,$h=25,$rand=true)
例2,代码如下:
-
<?php
-
$id=$_GET[id];
-
include("admin/config.php");
-
$sql="select * from user where id=$id";
-
$data=mysql_fetch_array(mysql_query($sql));
-
$p=SBC_DBC($data[Phone],1);
-
function get_str($str,$strlen=16) {
-
$str=stripslashes($str);
-
for($i=0;$i<$strlen;$i++)
-
if(ord(substr($str,$i,1))>0xa0) $j++;
-
if($j%2!=0) $strlen++;
-
$tmp_str=substr($str,0,$strlen);
-
return $tmp_str;
-
}
-
if($p<>''){
-
-
Header("Content-type:image/png");
-
-
-
$nwidth=120;
-
$nheight=25;
-
$im=@imagecreate($nwidth,$nheight) or die("Can't initialize new GD image stream");
-
-
-
$background_color=imagecolorallocate($im,255,255,255);
-
$text_color=imagecolorallocate($im,23,14,91);
-
-
-
imagefilledrectangle($im,0,0,$nwidth-1,$nheight-1,$background);
-
imagerectangle($im,0,0,$nwidth-1,$nheight-1,$background_color);
-
-
-
-
$randval=$p;
-
imagestring($im,8,10,2,$randval,$text_color);
-
-
-
-
-
-
-
-
|