PHP: Generate random number and string

Here are code samples to generate random number and strings in PHP. Generate random numbers between 1 and 1000 $num = rand(1,1000); Using mtrand() function for better random number generation $num = mt_rand(1,1000); Generate a unique combination of numbers and letters. Works with PHP5 and higher. $unique = uniqid(); Using md5() and uniqid() function to … Read more

PHP: Validate Email, Name, Price, Age using Regular Expression & filter_var

This article contains PHP code with regular expression to validate different numbers and strings. Integer validation can be done for validating age. Decimal validation can be done for validating price. Simple String validation can be done for validating name. Email validation can be done for validating email. preg_match PHP function is used to perform the … Read more

Making a tree navigation menu in PHP

Below is the code with sufficient comments on making a tree navigation menu (hierarchical menu) in PHP. A single page holding different links. The navigation links are present at the left sidebar of the page. I have not used any dynamic approach over here. Have not used any loop. It’s just a static and straight-forward … Read more