search
Homephp教程php手册可以让PHP编程事半功倍的类库

可以让PHP编程事半功倍的类库

Jun 13, 2016 am 10:53 AM
phpGet twice the result with half the effortuseCanobjectmethodofClass libraryprogrammingFor

在用php开发网站的时候,使用面向对象的方法确实可以提高代码复用率,减少代码冗余。而对初学者更友好的是,PHP开发网站所需要的大部分类库,网上都有十分优秀的类库存在了。作为一个程序猿当然不能重复制造轮子,所以我把平时经常会使用到的类库整理下来,希望对学习PHP的站长朋友们有用。

一:采集类库,snoopy.class.php。(类库下载请自行百度,没有重名的)

说起做网站对大部分站长来讲,采集是必不可缺的部分。很多站长可能直接使用dedecms之类cms内置的采集功能了,但是有时候网站很小没必要使用cms或者cms的内置采集功能满足不了我们的需求的时候怎么办呢。那就可以使用这个采集类库了。使用方法非常简单。

使用演示:

//加载类库文件include("snoopy.php");

//要采集的页面地址

$url = "http://www.www.shlongyingjixie.com";  

$snoopy = new Snoopy;

//去抓取页面

$snoopy->fetch($url);

//输出抓回页面的html  

echo $snoopy->results;

接下来,用正则表达式把你需要的内容匹配出来。这样采集就大功告成了。简单吧!

二:图片处理类库,PHPThumb,下载地址(github.com/masterexploder/PHPThumb)。注意这个类库有一个重名的叫phpthumb,只是大小写的差别,所以查找文档的时候千万注意。

在网站建设过程中,需要处理图片的地方多不胜数,用php的图片函数处理图片,十分繁琐。而且对新手来讲十分不好掌握。现在我们可以用PHPThumb类库来处理图片,包括,图片尺寸调整,图片截取,图片加水印,图片旋转等等功能。

使用演示:

//加载类库文件

require_once 'path/to/ThumbLib.inc.php';

//实例化类库,传入你要处理的图片的地址可以是网络地址,也可以是本地地址

$thumb = PhpThumbFactory::create('http://www.shlongyingjixie.com/');

//把图片等比缩小到最大宽度 100px或者最高100px,当只输入一个参数的时候,是限制最宽的尺寸。

$thumb->resize(100, 100);

//把图片等比缩小到原来的百分数,比如50就是原来的50%。

$thumb->resizePercent(50);

//截取一个175px * 175px的图片,注意这个是截取,超出的部分直接裁切掉,不是强制改变尺寸。

$thumb->adaptiveResize(175, 175);

//从图片的中心计算,截取200px * 100px的图片。

$thumb->cropFromCenter(200, 100);

//截图,前两个参数分别是需要解出的图片的右上角的坐标X,Y。 后面两个参数是需要解出的图片宽,高。

$thumb->crop(100, 100, 300, 200);

//把图片顺时针反转180度

$thumb->rotateImageNDegrees(180);

这个类库还有更多功能就不多做介绍了,如果你也在开发PHP网站过程中需要处理图片不妨阅读一下这个类库的文档,保证你处理图片很简单,再也不用和那十几个烦人的php图片处理函数打交道了!转载请注明:http://www.shlongyingjixie.com

 

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools