可以让PHP编程事半功倍的类库
在用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

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

Pythonempowersbeginnersinproblem-solving.Itsuser-friendlysyntax,extensivelibrary,andfeaturessuchasvariables,conditionalstatements,andloopsenableefficientcodedevelopment.Frommanagingdatatocontrollingprogramflowandperformingrepetitivetasks,Pythonprovid
