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: