PHP

Regex for mail

In: JavaScript|PHP

13 Jul 2010

In order to validate mail address, you can use regex or some other validation format, but regex is more common. So, here is regex for mail validation: /^([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)$/i Next snippets will show you how to use regex for mail in PHP and JavaScript in order to validate users e-mail. Regex for mail in PHP: 1 [...]

PHP thumbnail generator

In: PHP

12 Jul 2010

On almost every website, we need a image thumbnail generator since we don’t want to load whole images to users computer. Here is a snippet of PHP thumbnail generator, that helps you create thumbnails of your images. However, this PHP thumbnail generator is not very wise, and shouldn’t be used on high traffic websites since [...]

Getimagesize PHP

In: PHP

11 Jul 2010

Getimagesize is a PHP function that can be useful when printing your image in HTML, as img attributes width and height are necessary if you want to have valid HTML. However, getimagesize function will not only be helpful when working with images. It will also help you determine size of uploaded flash (SWF). This can [...]

PHP generate password

In: PHP

9 Jul 2010

Have you ever wondered how to generate password in PHP? With PHP generate password function it can be really easy task. You just need to send the length of generated password, od add/remove some characters from $password variable. 1 2 3 4 5 function generate_password($length) { $password = str_shuffle(’abcefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()_+;[]\/.,<>’); //return generated password return substr($password , [...]

PHP unique id

In: PHP

9 Jul 2010

To generate PHP unique id, you can use PHP function uniqid(). This PHP function generates a prefixed unique identifier based on the current time in microseconds. 1 2 //returns 13 character long unique id echo uniqid(); If you want to generate identifiers simultaneously on different servers, they might try to generate identifier at the same [...]

PHP list dir

In: PHP

9 Jul 2010

Many times I have written functions for reading directory list. It was quite a horrible code until I found glob() – a PHP list dir function. So, in order to make life easier, here’s a snippet that shows you how to use this PHP list dir function: 1 2 3 4 5 6 $dir = [...]

PHP display errors

In: PHP

8 Jul 2010

When putting our PHP website online, good practice is not to display errors and notices, because they leave a user with an experience of visiting bad – unprofessional website. Still, when you are visiting your PHP website, you want to have display errors turned on, so you know what went wrong in some cases, and [...]

In order to make your WordPress trash empty every couple of days, open your wp-config.php file and paste the following snippet: //empty WordPress trash once a week define(’EMPTY_TRASH_DAYS’, 7);

If you want to prevent client from switching WP theme by accident, use this WP snippet, brought to you by SoulSizzle design. Just put this code into your functions.php file, and users won’t have an option to switch theme in WP. 1 2 3 4 5 6 7 add_action(’admin_init’, ‘remove_theme_menus’); function remove_theme_menus() { global $submenu; [...]

PHP user agent

In: PHP

8 Jul 2010

Many websites would not deliver you content if you came presenting as a wrong user agent. In PHP there are ways to present yourself as someone else if you are going to crawl somebody’s website. In this snippet we show you how to use PHP user agent settings in cURL, and trick server to think [...]