Home > Backend Development > PHP Tutorial > PHP mobile phone number generation picture example program_PHP tutorial

PHP mobile phone number generation picture example program_PHP tutorial

WBOY
Release: 2016-07-13 10:48:30
Original
1554 people have browsed it

We have built a recruitment website before, so we need to prevent others from collecting our customers’ mobile phone numbers and email addresses, so we will use PHP to directly generate a picture from the mobile phone numbers and email addresses read from the database. , in the past, the collection could only be pictures and could not be recognized. Let me introduce two examples to you.


PHP string processing - save mobile phone number as picture

The code is as follows Copy code
 代码如下 复制代码

   ////电话号码转变成图片
//$str 要显示的字串,$rand是否启用扰码
function str_to_image($str,$w=130,$h=25,$rand=true)
{
//生成11位的数字图片
Header("Content-type:image/png"); //告诉浏览器,下面的数据是图片,而不要按文字显示
//定义图片宽高
$nwidth=$w;
$nheight=$h;
//srand((double)microtime()*1000000); //取得目前时间的百万分之一秒值,以执行时的百万分之一秒当乱数种子
$randval=$str; //11位数
$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); //点
}
}
//imagestring($im,3,5,5,"A Simple Text String",$text_color);
//imageinterlace($im,1);
imagepng($im); //建立png图型
imagedestroy($im); //结束图型
}

$str = '13087263453';
echo str_to_image($str,$w=130,$h=25,$rand=true)

////Convert phone number into picture<🎜> //$str The string to be displayed, $rand whether to enable scrambling<🎜> Function str_to_image($str,$w=130,$h=25,$rand=true)<🎜> {<🎜> //Generate an 11-digit digital image <🎜> ​​​ Header("Content-type:image/png"); //Tell the browser that the following data is an image, rather than displaying it as text <🎜> //Define image width and height <🎜>         $nwidth=$w;<🎜>         $nheight=$h;<🎜> //srand((double)microtime()*1000000); //Get the millionth of a second value of the current time, and use the millionth of a second at execution time as the random number seed <🎜>          $randval=$str; //11 digits <🎜>          $im=@imagecreate($nwidth,$nheight) or die("Can't initialize new GD image stream"); ​​//Create image <🎜> //Picture color settings <🎜> $background_color=imagecolorallocate($im,255,255,255); //Matching color <🎜> $text_color=imagecolorallocate($im,23,14,91);<🎜> //Draw picture border <🎜> Imagefilledrectangle($im,0,0,$nwidth-1,$nheight-1,$background); //Rectangular area coloring <🎜> Imagerectangle($im,0,0,$nwidth-1,$nheight-1,$background_color); //Draw a rectangle <🎜> Imagestring($im,8,10,4,$randval,$text_color); //Draw horizontal string <🎜>          if($rand){<🎜> //Add interference factors <🎜> 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); //Point <🎜>            }<🎜> }<🎜> //imagestring($im,3,5,5,"A Simple Text String",$text_color); <🎜> //imageinterlace($im,1); <🎜>          imagepng($im); //Create png graphics <🎜>         imagedestroy($im); //End graphic<🎜> }<🎜> <🎜> $str = '13087263453';<🎜> echo str_to_image($str,$w=130,$h=25,$rand=true)<🎜>

例2

 代码如下
代码如下 复制代码


$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<>''){
//生成5位的数字图片
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); //绘制矩形

//srand((double)microtime()*1000000); //取得目前时间的百万分之一秒值,以执行时的百万分之一秒当乱数种子
//$randval=rand();
$randval=$p; //5位数
imagestring($im,8,10,2,$randval,$text_color); //绘制横式字串


//加入干扰因素
//for($i=0;$i<478;$i++)
//{
//$randcolor=imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255));
//imagesetpixel($im,rand()%100,rand()%30,$randcolor); //点
//}
//imagestring($im,3,5,5,"A Simple Text String",$text_color);
//imageinterlace($im,1);
imagepng($im); //建立png图型
imagedestroy($im); //结束图型

}else{
echo "商家未输入电话号码";
}

?>

复制代码

$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<>''){
//生成5位的数字图片
Header("Content-type:image/png"); //告诉浏览器,下面的数据是图片,而不要按文字显示

//定义图片宽高
$nwidth=120;
$nheight=25;
$im=@imagecreate($nwidth,$nheight) or die("Can't initialize new GD image stream"); //建立图象

//绘制图片边框
imagefilledrectangle($im,0,0,$nwidth-1,$nheight-1,$background); //矩形区域着色
imagerectangle($im,0,0,$nwidth-1,$nheight-1,$background_color); //绘制矩形
//srand((double)microtime()*1000000); //取得目前时间的百万分之一秒值,以执行时的百万分之一秒当乱数种子
//$randval=rand();
$randval=$p; //5位数
imagestring($im,8,10,2,$randval,$text_color); //绘制横式字串

//加入干扰因素
//for($i=0;$i<478;$i++)
//{
//$randcolor=imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255));
//imagesetpixel($im,rand()%100,rand()%30,$randcolor); //点
//}
//imagestring($im,3,5,5,"A Simple Text String",$text_color);
//imageinterlace($im,1);
imagepng($im); //建立png图型
imagedestroy($im); //结束图型
}else{
echo "商家未输入电话号码";
}
?>
http://www.bkjia.com/PHPjc/632785.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/632785.htmlTechArticle以前做过一个招聘网站这样我们需要让别有采集不到我们客户的手机号码与邮箱地址了,所以我们会利用php实现从数据库读出来的手机号码...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template