Profile
Achievement
apphp-snippets's Recent PHP Snippets
- All /
This code allows to calculate the full size of a directory using PHP.
0
955
posted 6 years ago by apphp-snippets
This code allows to perform a query to WhoIs service in PHP.
0
860
posted 6 years ago by apphp-snippets
This example shows you how to create redirection o another directory. It may be useful, for example, when you have a project, placed in sub-directory.
0
854
posted 8 years ago by apphp-snippets
Sometimes you may need to change image properties 'on-the-fly'. The best example is when you want to display blog post short description, retrieve the first image and try to turn it into the thumbnail: change some properties and add a special class n...
0
755
posted 9 years ago by apphp-snippets
This simple code demonstrates how to change automatically site language, according to the visitor's country. If you implement this script in your site it will open the page in the language of your visitor.
0
987
posted 9 years ago by apphp-snippets
This example shows you how to remove file extension from URLs using .htaccess file directives. Remember, that "mod_rewrite" works only on Apache server. Before trying please be sure that you are working on Apache server and the "mod_rewrite" module/e...
0
786
posted 10 years ago by apphp-snippets
We know that normally index.html or index.php is the default page for many servers, when visitor types a directory without specifying a file name. You can change this rule with .htaccess:
0
755
posted 10 years ago by apphp-snippets
This code demonstrates a simple way to validate IP address using preg_match() PHP function. This is a very simple code, that allows you to perform this task quickly with a minimum lines of code.
0
807
posted 10 years ago by apphp-snippets
This code demonstrates how to create and parse the JSON data format of using array of PHP. It's a very simple code, that allows you to perform this task.
0
854
posted 10 years ago by apphp-snippets
This simple function allows you to getect a country code and city of your site visitors, using the www.geoplugin.net service. You may use this data to add default values in registration form or use it for any other purposes, like blocking access to y...
0
1106
posted 10 years ago by apphp-snippets
This example shows you how to define custom error pages in .htaccess file and also how to display the error page on your site. You may create separate files for each error, described in Sample 1 or just create the one PHP file for Sample 2. Here...
0
745
posted 10 years ago by apphp-snippets
This example of code shows how to do a simple POST request in PHP to another web server by using a socket connection.
0
1535
posted 11 years ago by apphp-snippets
With increasing of popularity of WordPress script, Gravatars have become a really quite popular. Now you may easy integrate them into your own script as they provide a very easy to use API.
0
480
posted 11 years ago by apphp-snippets
Usually when you're using different CSS files on your site, they might take a quite long to be loaded. Using this PHP code, you can compress them into a single file with no unnecessary white spaces or comments. Why we need to compress multiple CSS fi...
0
610
posted 11 years ago by apphp-snippets
This code allows to remove all duplicate elements from an array using PHP array_unique() function.
0
843
posted 11 years ago by apphp-snippets
This snippet allows you set a limitation for download rate of the file that visitors download from your site.
1
1020
posted 11 years ago by apphp-snippets
This code shows how to parse XML file in easy way using PHP.
0
770
posted 11 years ago by apphp-snippets
This code allows to list the contents of any given directory.
1
698
posted 11 years ago by apphp-snippets
This code allows to pass filename in the $file_name variable and function will return file extension only.
0
732
posted 11 years ago by apphp-snippets
This function returns the duration of the given time period in days, hours, minutes and seconds. For example: echo convertSecToStr('654321'); would return "7 days, 13 hours, 45 minutes, 21 seconds"
0
774
posted 11 years ago by apphp-snippets
You may retrieve all needed file path data using PHP's built-in function pathinfo. You don't need to create your own functions or use regular expressions to get this info. It was already been created for this purpose.
0
931
posted 11 years ago by apphp-snippets
Sometimes you need to generate passwords for customers automatically when a new account is created. This code allows you choose the desired length and strength for the password and it is very flexible.
0
530
posted 11 years ago by apphp-snippets
Encodes the given data with MIME base64. Base64-encoded data takes about 33% more space than the original data.
0
871
posted 11 years ago by apphp-snippets
This is a very common PHP question of HOW TO remove last character from string in PHP. Find below some ways how to delete last character from string in PHP.
0
1392
posted 11 years ago by apphp-snippets
This function highlight_string() outputs or returns a syntax highlighted version of the given PHP code using the colors defined in the built-in syntax highlighter for PHP.
0
537
posted 11 years ago by apphp-snippets
The mail() function allows you to send emails directly from a script. Remember, that most of shared hosting providers require (for security reasons) to use the domain name of your hosting in "FROM" email, e.g. [email protected] for http://yourdomai...
1
764
posted 11 years ago by apphp-snippets
If you work with Twitter, you probably use a url shortener such as tinyurl.com or bit.ly to share/post your favorite blog posts or important messages with links on the network. This snippet take your url as a parameter and returns a short url.
0
776
posted 11 years ago by apphp-snippets
You may use this code to highlight specific words in your displaying search results.
3
770
posted 11 years ago by apphp-snippets
This code removes all special characters from the given URL and make it SEO friendly.
2
697
posted 11 years ago by apphp-snippets
Allows to perform PHP redirection (must be placed before any browser output).
0
579
posted 11 years ago by apphp-snippets