Ubuntu 10.10 Pentax K-5

Saturday, December 02, 2017

regex 中文

在javascript中,要判断字符串是中文是很简单。比如:
1
2
3
4
5
6
var str = "php编程";
if (/^[\u4e00-\u9fa5]+$/.test(str)) {
alert("该字符串全部是中文");
else {
alert("该字符串不全部是中文");
}
 PHP正确匹配中文方式, “u" for utf-8 mode
1
2
3
4
5
6
$str = "php编程";
if (preg_match("/^[\x{4e00}-\x{9fa5}]+$/u",$str)) {
print("该字符串全部是中文");
else {
print("该字符串不全部是中文");
}

Tuesday, November 28, 2017

QRCode Generator in Php

phpqrcode http://phpqrcode.sourceforge.net/ can be used to generate qrcode in php.

It supports to generate the code and save to external file or export to browser.

ob_start();
\PHPQRCode\QRcode::png('http://www.chatcai.tk/player-chatroom/register?code='.$model->invitation_code, null, 'L', 4, 2);
$imageString = base64_encode( ob_get_contents() );
ob_end_clean();