Home  >  Article  >  Backend Development  >  Class library that can make PHP programming twice the result with half the effort_PHP tutorial

Class library that can make PHP programming twice the result with half the effort_PHP tutorial

WBOY
WBOYOriginal
2016-07-14 10:07:51900browse

When developing a website with PHP, using object-oriented methods can indeed improve the code reuse rate and reduce code redundancy. What is more friendly to beginners is that most of the class libraries required for PHP website development are already available online. Of course, as a programmer, I cannot reinvent the wheel, so I have sorted out the class libraries that I often use in my daily life. I hope it will be useful to webmaster friends who are learning PHP.

1: Collection class library, snoopy.class.php. (Please download the class library from Baidu, there are no duplicate names)

When it comes to building a website, collection is an indispensable part for most webmasters. Many webmasters may directly use the built-in collection function of cms such as dedecms, but sometimes the website is too small and there is no need to use cms or what should we do when the built-in collection function of cms cannot meet our needs. Then you can use this collection class library. The usage is very simple.

Usage demo:

//Load the class library file include("snoopy.php");

//The page address to be collected

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

$snoopy = new Snoopy;

//Go to crawl the page

$snoopy->fetch($url);

//Output the html of the retrieved page

echo $snoopy->results;

Next, use regular expressions to match the content you need. In this way, the collection is complete. Keep it simple!

Two: Image processing library, PHPThumb, download address (github.com/masterexploder/PHPThumb). Note that this class library has an identical name called phpthumb, the only difference is in upper and lower case, so be careful when searching for documentation.

In the process of website construction, there are countless places where images need to be processed. It is very cumbersome to use PHP image functions to process images. And it is very difficult for novices to master. Now we can use the PHPThumb class library to process images, including image resizing, image interception, image watermarking, image rotation and other functions.

Usage demo:

//Load class library file

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

//Instantiate the class library, and pass in the address of the image you want to process, which can be a network address or a local address

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

//Reduce the image proportionally to the maximum width of 100px or up to 100px. When only one parameter is entered, it is the widest size limit.

$thumb->resize(100, 100);

//Reduce the image to the original percentage, for example, 50 is 50% of the original.

$thumb->resizePercent(50);

//Intercept a 175px * 175px picture. Note that this is an interception, and the excess part is directly cropped, not forced to change the size.

$thumb->adaptiveResize(175, 175);

//Calculate from the center of the image and intercept the 200px * 100px image.

$thumb->cropFromCenter(200, 100);

//Screenshot, the first two parameters are the coordinates X and Y of the upper right corner of the picture to be solved. The next two parameters are the width and height of the image that needs to be solved.

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

//Reverse the picture 180 degrees clockwise

$thumb->rotateImageNDegrees(180);

This class library has more functions, so I won’t introduce them in detail. If you also need to process images when developing a PHP website, you may wish to read the documentation of this class library to ensure that it is very simple for you to process images, and you no longer have to deal with images. Dealing with those dozen annoying php image processing functions! Please indicate when reprinting: http://www.shlongyingjixie.com

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/477841.htmlTechArticleWhen developing a website with PHP, using object-oriented methods can indeed improve the code reuse rate and reduce code redundancy. Remain. What’s more friendly to beginners is that most of what is needed to develop a website in PHP...
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