Collected 21 practical and convenient PHP function code

Source: Internet
Author: User
The 21 practical and convenient PHP function codes compiled here are suitable for direct use and learning reference during php development, which will be helpful to PHP developers of every type.

The 21 practical and convenient PHP function codes compiled here are suitable for direct use and learning reference during php development, which will be helpful to PHP developers of every type.

PHP is currently the most widely used Web-based programming language that drives millions of websites, including some large websites such as Facebook. 21 practical and convenient PHP code excerpts are collected here, which will be helpful for every type of PHP developers.

1. PHP can read random strings

This Code creates a readable string that is closer to a word in the dictionary and is practical and password-verified.

2. PHP generates a random string

If you do not need readable strings, use this function instead to create a random string as your random password.

3. PHP-encoded email address

This code can be used to encode any email address as an html character entity to prevent being collected by spam programs.

4. PHP verification email address

Email verification may be the most common web form verification. In addition to verifying the email address, this code can also choose to check MX records in the DNS to which the email domain belongs, making email verification more powerful.

5. PHP listing directory content

6. PHP destroy directory

Delete a directory, including its contents.

7. parse JSON data in PHP

Like most popular Web services, such as twitter, which provides data through open APIs, it always knows how to parse various transfer formats of API data, including JSON and XML.

8. PHP parses XML data

9. Name scaling of PHP creation logs

Create a user-friendly log scaling name.

10. PHP obtains the real IP address of the client.

This function will obtain the real IP address of the user, even if he uses the proxy server.

11. PHP mandatory File Download

It provides users with mandatory File Download functions.

12. Create a tag cloud in PHP

13. Search for similarity between two strings in PHP

PHP provides a rarely used similar_text function, but this function is very useful for comparing two strings and returning a percentage of similarity.

14. Use the Gravatar profile picture in PHP applications

As WordPress becomes increasingly popular, Gravatar also becomes popular. Gravatar provides easy-to-use APIs, making it easy to include them in applications.

15. PHP truncates text at the character breakpoint

Word break refers to the place where a word can be broken when it is switched. This function truncates the string at the break.

16. Zip compression of PHP files

17. decompress the Zip file in PHP.

18. PHP presets the http string for the URL address

Sometimes you need to accept URL input in some forms, but few users add http: // fields. This code will add this field to the URL.

19. PHP converts the URL string into a hyperlink

This function converts the URL and e-mail address strings into clickable superlinks.

20. PHP adjusted image size

Creating image thumbnails takes a long time. This Code helps you understand the thumbnails logic.

21. PHP detects ajax requests

Most JavaScript frameworks, such as jquery and Mootools, send additional HTTP_X_REQUESTED_WITH header information when sending Ajax requests. The header is an ajax request, therefore, you can detect Ajax requests on the server side.

English version:

Translation:

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.