Home > Backend Development > PHP Tutorial > 批改一些PHP工具

批改一些PHP工具

WBOY
Release: 2016-06-13 12:08:36
Original
1286 people have browsed it

修改一些PHP工具

原来的代码 在非框架下是木有问题的,但是用在框架下就报错,mb的,终于修改好了...?

?

具体使用见附件,可以自己封装下 呵呵

?

/** * 二维码图像生成 */class Helper_Qrcode {	/**	 * 生成二维码图片	 * 	 * @param  string  $url 对应的url地址	 * @param  integer $size 图像大小	 * @param  integer $margin 边距	 *	 * @return QView_Output 包含二维码图像的输出对象	 */	static function generateImage($url,$size=6,$margin=1)	{		$filename = 'qkenrcode-' . mt_rand();		ob_start();		$mime = image_type_to_mime_type(IMAGETYPE_GIF);		$qr = QRCode::getMinimumQRCode($url, QR_ERROR_CORRECT_LEVEL_H);		$im = $qr->createImage($size, $margin);		imagegif($im);		imagedestroy($im);				unset($im);		$output = new QView_Output($filename, $mime, ob_get_clean());		$output            ->contentDisposition('inline')            ->enableClientCache(false);		return $output;	}}
Copy after login

?

/** * 地理位置相关辅助类 * */class Helper_Geo {	private static function trueIp($ip)	{		return filter_var($ip,FILTER_VALIDATE_IP,			FILTER_FLAG_IPV4|FILTER_FLAG_IPV6|			FILTER_FLAG_NO_RES_RANGE|FILTER_FLAG_NO_PRIV_RANGE);	}	/**	 * 根据 ip 地址计算对应的 地标信息 	 * 	 * @param   $ip IP 地址	 * 	 * @return array	 */	static function getData($ip)	{		$ip = self::trueIp($ip);		if ( $ip )		{			Unirest::verifyPeer(false);			Unirest::timeout(2);			$response = Unirest::get('http://ip.taobao.com/service/getIpInfo.php', 				array( "Accept" => "application/json" ),				array( "ip" => $ip ));			if ( is_array($response->body) && $response->body['code'] === 0 && !empty($response->body['data']) )			{				return $response->body['data'];			}     	}		return false;	}}
Copy after login

?

?

Related labels:
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