PHP: Parse Unparse String Array

Here is a quick tip on parsing and unparsing string and array in PHP. You can parses the string into variables by using the parse_str PHP function. Using parse_str function void parse_str ( string $str [, array &$arr ] ) $str = The input string. $arr = If the second parameter arr is present, variables … Read more

PHP: How to get integer or decimal from a string?

Suppose, I have a string with text and number and I only want the number. I don’t want the characters and text of the string. Here is the way out:- In this example, you will get only integer. It will omit all characters and text from the string. $string = 'Nrs 89,994,874.0098'; echo preg_replace("/[^0-9]/", '', … Read more

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