Signup/Sign In

Answers

All questions must be answered. Here are the Answers given by this user in the Forum.

You need to set the value of upload_max_filesize and post_max_size in your php.ini :
***
; Maximum allowed size for uploaded files.
upload_max_filesize = 40M

; Must be greater than or equal to upload_max_filesize
post_max_size = 40M
***
After modifying php.ini file(s), you need to restart your HTTP server to use new configuration.

If you can't change your php.ini, you're out of luck. You cannot change these values at run-time; uploads of file larger than the value specified in php.ini will have failed by the time execution reaches your call to ini_set.
4 years ago
You can use the strval() function to convert a number to a string.

From a maintenance perspective its obvious what you are trying to do rather than some of the other more esoteric answers. Of course, it depends on your context.
***
$var = 5;

// Inline variable parsing
echo "I'd like {$var} waffles"; // = I'd like 5 waffles

// String concatenation
echo "I'd like ".$var." waffles"; // I'd like 5 waffles

// The two examples above have the same end value...
// ... And so do the two below

// Explicit cast
$items = (string)$var; // $items === "5";

// Function call
$items = strval($var); // $items === "5";
***
4 years ago
***
//
// A very simple PHP example that sends a HTTP POST to a remote site
//

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,"");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
"postvar1=value1&postvar2=value2&postvar3=value3");

// In real life you should use something like:
// curl_setopt($ch, CURLOPT_POSTFIELDS,
// http_build_query(array('postvar1' => 'value1')));

// Receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$server_output = curl_exec($ch);

curl_close ($ch);

// Further processing ...
if ($server_output == "OK") { ... } else { ... }
?>
***
4 years ago
***
//
// A very simple PHP example that sends a HTTP POST to a remote site
//

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,"");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
"postvar1=value1&postvar2=value2&postvar3=value3");

// In real life you should use something like:
// curl_setopt($ch, CURLOPT_POSTFIELDS,
// http_build_query(array('postvar1' => 'value1')));

// Receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$server_output = curl_exec($ch);

curl_close ($ch);

// Further processing ...
if ($server_output == "OK") { ... } else { ... }
?>
***
4 years ago
***
foreach($array as $key=>$value) {
// do stuff
}
***
$key is the index of each $array element
4 years ago
Use print_r:
***
$myText = print_r($myVar,true);
***
You can also use it like:
***
$myText = print_r($myVar,true)."foo bar";
***
This will set $myText to a string, like:
***
array (
0 => '11',
)foo bar
Use var_export to get a little bit more info (with types of variable,...):

$myText = var_export($myVar,true);
***
4 years ago
Use the second parameter of json_decode to make it return an array:
***
$result = json_decode($data, true);
***
4 years ago
You can use number_format():
***
return number_format((float)$number, 2, '.', '');
***
Example:
***
$foo = "105";
echo number_format((float)$foo, 2, '.', ''); // Outputs -> 105.00
***
4 years ago
DB::QueryLog() works only after you execute the query using $builder->get().

If you want to get the raw query before or without executing the query, you can use the $builder->toSql() method.

Example to get the raw SQL and to replace '?' with actual binding values:
***
$query = str_replace(array('?'), array('\'%s\''), $builder->toSql());
$query = vsprintf($query, $builder->getBindings());
dump($query);

$result = $builder->get();
***
Or you can deliberately trigger an error, for example, by using a non-existent table or column. Then you can see the generated query in the exception message.
4 years ago
In C++11, you can use std::to_string, e.g.:
***
auto result = name + std::to_string( age );
***
4 years ago
You can use std::find from :
***
#include
#include
vector vec;
//can have other data types instead of int but must same datatype as item
std::find(vec.begin(), vec.end(), item) != vec.end()
***
This returns a bool (true if present, false otherwise). With your example:
***
#include
#include

if ( std::find(vec.begin(), vec.end(), item) != vec.end() )
do_this();
else
do_that();
***
4 years ago
Given a parent class named Parent and a child class named Child, you can do something like this:
***
class Parent {
public:
virtual void print(int x);
};

class Child : public Parent {
void print(int x) override;
};

void Parent::print(int x) {
// some default behavior
}

void Child::print(int x) {
// use Parent's print method; implicitly passes 'this' to Parent::print
Parent::print(x);
}
***
Note that Parent is the class's actual name and not a keyword.
4 years ago