php 之 簡單中文驗證

2021-06-02 06:36:24 字數 1222 閱讀 1427

img.php

<?php 

session_start();

/*for($i=0;$i<4;$i++)

$_session[check_pic] = $rand;

*/$image = imagecreatetruecolor(100, 30);

$bg = imagecolorallocate($image, 0, 0, 0);

$color = imagecolorallocate($image, 255, 255, 255);

//imagestring($image, rand(1,6), rand(3,60), rand(3,15), $rand, $color);

for($i=0;$i<3;$i++)

//rand() ---->0-max 不大於100

for($i=0;$i<200;$i++)

//$str = iconv("gbk", "utf-8", "中");

$str = "中國";

$_session[check_pic] = $str;

//解決中文,頁面本身為utf-8

$str = mb_convert_encoding($str, "html-entities","utf-8" );

//2:字型大小 3:傾斜角度 x , y 座標

imagettftext($image, 12, 0, 20, 20, $color, 'msyh.ttf', $str);

//輸出

header("content-type: image/jpeg;charset=utf-8");

imagejpeg($image);

/*修改eclipse的配置,可以使得eclipse的新建專案的預設編碼直接為utf-8

在選單欄的

window->preferences->general->workspace->text file encoding

將其改為uft-8即可。*/

?>

sub.php

<?php 

header("content-type: text/html;charset=utf-8");

session_start();

if($_post[check]) else }

?>

歡迎批評指教!

php使用正則驗證中文

php用preg match來匹配並判斷乙個字串中是否含有中文或者都是中文的程式設計客棧方法如下 str php學習部落格 if preg match x7f xff str else if preg match x7f xff 程式設計客棧str else 程式設計客棧 以上程式的輸出的結果為 字...

php筆記之表單驗證

1.php 2.php header content type text html charset utf8 設定頁面編碼 第一步,接收前面表單中的值 乙個,username 接收 post username echo post username 空字串也是資料 使用isset 驗證是否正常提交是很...

PHP之驗證碼

1 header content type image jpeg 4 驗證碼函式 5function getverify type 4 2021 建立畫布 22 width 500 23 height 300 2425 image imagecreatetruecolor width,height ...