This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // source: http://www.apphp.com/index.php?snippet=php-compress-multiple-css-files | |
| header('Content-type: text/css'); | |
| ob_start('compress_css'); | |
| function compress_css($buffer) { | |
| /* remove comments in css file */ | |
| $buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer); | |
| /* also remove tabs, spaces, newlines, etc. */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # display no errs to user | |
| # source: http://www.apphp.com/index.php?snippet=htaccess-error-logging | |
| php_flag display_startup_errors off | |
| php_flag display_errors off | |
| php_flag html_errors off | |
| # log to file | |
| php_flag log_errors on |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!-- You may place favicon.ico and apple-touch-icon.png in the root of your domain and simply remove these references --> | |
| <!-- source: http://www.apphp.com/index.php?snippet=html-favicon-and-apple-icons --> | |
| <link rel="shortcut icon" href="/favicon.ico"> | |
| <link rel="apple-touch-icon" href="/apple-touch-icon.png"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <style type="text/css"> | |
| @media screen and (-webkit-min-device-pixel-ratio:0) { | |
| H5 { color:red; } | |
| P { margin-left:20px; } | |
| /* other special styles for Chrome here */ | |
| } | |
| </style> | |
| // source: http://www.apphp.com/index.php?snippet=css-targeting-chrome-only |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| This example of code allows you to create a new object in javascript (using simple inheritance) | |
| such that the class of the object is defined from a variable. After creating the object you may use | |
| it for your purposes. | |
| source: http://www.apphp.com/index.php?snippet=javascript-create-object-from-variable | |
| */ | |
| <script type="text/javascript"> | |
| var className = "PluginClass"; | |
| // get a reference to the class object itself | |
| // (we've assumed the class is defined in a global scope) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 name. source: http://www.apphp.com/index.php?snippet=php-change-image-properties-on-fly | |
| <?php | |
| $postText = '..includes html + image tags'; | |
| // find first image and redo it | |
| preg_match_all('/<img[^>]+>/i', $postText, $images); | |
| $postThumbnail = isset($images[0][0]) ? $images[0][0] : ''; | |
| $postThumbnail = preg_replace('/(width|height|style)="*"/', '', $postThumbnail); | |
| $postThumbnail = preg_replace('/<img/', '<img class="blog-post-thumbnail"', $postThumbnail); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. | |
| source: http://www.apphp.com/index.php?snippet=php-change-language-according-to-visitor-country | |
| <?php | |
| // prepare reload to local version according by first visit | |
| session_start(); | |
| $location_reload = isset($_SESSION["loc_reload"]) ? (bool)$_SESSION["loc_reload"] : false; | |
| // prepare reload to local version according by first visit | |
| if(!$location_reload){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| 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: | |
| Source: http://www.apphp.com/index.php?snippet=htaccess-different-directory-index-page#null | |
| */ | |
| # Sample 1: | |
| DirectoryIndex index2.html | |
| # Sample 2: | |
| DirectoryIndex index2.php |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| 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/extension is enabled. | |
| Source: http://www.apphp.com/index.php?snippet=htaccess-remove-file-extention-from-url | |
| */ | |
| # Sample 1: | |
| RewriteRule ^about$ about.php [L] | |
| # Sample 2: | |
| RewriteCond /%{REQUEST_FILENAME}.php -f |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| This is a very simple snippet about how to create a database 1st, | |
| a user and then assign some privileges to the user to allow him/her to | |
| perform some specific actions like insert, create, update, select etc. | |
| Source: http://www.apphp.com/index.php?snippet=mysql-create-database-and-assign-user | |
| */ | |
| -- Create database, user and grant all privileges | |
| CREATE DATABASE database_name; | |
| CREATE USER 'user_name'@'localhost' IDENTIFIED BY 'password'; |