Class libraries that allow PHP to be programmed with less effort

Source: Internet
Author: User
Tags learn php

When developing a Web site in PHP, using an object-oriented approach can actually improve code reuse and reduce code redundancy. And for beginners more friendly is, PHP development site needs most of the class library, online have very good class inventory in the. As a program ape of course can not repeat the wheel, so I usually use the class library to organize down, I hope to learn PHP webmaster friends useful.

One: Collection Class library, snoopy.class.php.

Download: (http://www.php100.com/html/download/pl/2013/0111/9090.html)

Say to do a website to most stationmaster, collect is essential part. A lot of webmaster may directly use dedecms such as CMS built-in collection function, but sometimes the site is very small do not need to use CMS or CMS built-in collection function can not meet our needs when to do it. Then you can use this collection class library. The use method is very simple.

Simple illustration:

Use Demo:

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

Address of the page to be collected

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

$snoopy = new Snoopy;

To crawl the page

$snoopy->fetch ($url);

Output the HTML of the scratch back page

Echo $snoopy->results;

Next, use regular expressions to match the content you need. So the collection is done. It's easy!

Second: Image processing Class library, Phpthumb

Download address (GITHUB.COM/MASTEREXPLODER/PHPTHUMB).

Note that this class library has a duplicate name called Phpthumb, but the difference between the case, so look for documents to be sure to pay attention.

In the site construction process, the need to deal with pictures of many places, with PHP picture function processing pictures, very cumbersome. And it is very difficult for beginners to master. Now we can use the Phpthumb class library to handle the picture, including, picture size adjustment, picture interception, picture watermark, picture rotation and so on function.

Use Demo:

Loading class library files

Require_once ' path/to/thumblib.inc.php ';

Instantiate the class library, and the address of the image you want to process can be either a network address or a local address

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

Reduce the picture to a maximum width of 100px or 100px, and when only one parameter is entered, it is the widest size.

$thumb->resize (100, 100);

Reduce the picture to the original percentage, such as 50 is the original 50%.

$thumb->resizepercent (50);

Capture a 175px * 175px image, note that this is intercepted, the excess part of the direct cut off, not forced to change the size.

$thumb->adaptiveresize (175, 175);

From the center of the picture, intercept the 200px * 100px picture.

$thumb->cropfromcenter (200, 100);

Screenshot, the first two parameters are required to solve the picture's upper right corner of the coordinate x,y. The following two parameters are needed to solve the picture wide and high.

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

Reverse the picture 180 degrees clockwise

$thumb->rotateimagendegrees (180);

This class library has more features do not introduce, if you are also in the development of PHP site needs to deal with the picture may wish to read this class library documents, to ensure that you deal with the picture is very simple, no longer with the more than 10 annoying PHP image processing functions to deal with!



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.