Cannot use object of type stdClass as array?
Use the second parameter of json_decode to make it return an array: $result = json_decode($data, true);
Use the second parameter of json_decode to make it return an array: $result = json_decode($data, true);
You can use number_format(): return number_format((float)$number, 2, ‘.’, ”); Example: $foo = “105”; echo number_format((float)$foo, 2, ‘.’, ”); // Outputs -> 105.00 This function returns a string.
Use sprintf : sprintf(‘%08d’, 1234567); Alternatively you can also use str_pad: str_pad($value, 8, ‘0’, STR_PAD_LEFT);
The short answer is NO, PDO prepares will not defend you from all possible SQL-Injection attacks. For certain obscure edge-cases. I’m adapting this answer to talk about PDO… The long answer isn’t so easy. It’s based off an attack demonstrated here. The Attack So, let’s start off by showing the attack… $pdo->query(‘SET NAMES gbk’); $var … Read more
Changing the memory_limit by ini_set(‘memory_limit’, ‘-1′); is not a proper solution. Please don’t do that. Your PHP code may have a memory leak somewhere and you are telling the server to just use all the memory that it wants. You wouldn’t have fixed the problem at all. If you monitor your server, you will see … Read more
PHP 5.4 offers the JSON_PRETTY_PRINT option for use with the json_encode() call. http://php.net/manual/en/function.json-encode.php <?php … $json_string = json_encode($data, JSON_PRETTY_PRINT);
As of PHP 5.3 there are two ways to define constants: Either using the const keyword or using the define() function: const FOO = ‘BAR’; define(‘FOO’, ‘BAR’); The fundamental difference between those two ways is that const defines constants at compile time, whereas define defines them at run time. This causes most of const‘s disadvantages. … Read more
Do you just mean spaces or all whitespace? For just spaces, use str_replace: $string = str_replace(‘ ‘, ”, $string); For all whitespace (including tabs and line ends), use preg_replace: $string = preg_replace(‘/\s+/’, ”, $string); (From here).
Try this, using mkdir: if (!file_exists(‘path/to/directory’)) { mkdir(‘path/to/directory’, 0777, true); } Note that 0777 is already the default mode for directories and may still be modified by the current umask.
$now = time(); // or your date as well $your_date = strtotime(“2010-01-31”); $datediff = $now – $your_date; echo round($datediff / (60 * 60 * 24));