Difference between PDO->query() and PDO->exec()

Regardless of whatever theoretical difference, neither PDO::query() nor PDO::exec() should be used anyway. These functions don’t let you bind parameters to the prepared statement and should never be used. Use prepare()/execute() instead, especially for UPDATE,INSERT,DELETE statements. Please note that although prepared statements are widely advertised as a security measure, it is only to attract people’s … Read more

How to send cookies with file_get_contents

First, this is probably just a typo in your question, but the third arguments to file_get_contents() needs to be your streaming context, NOT the array of options. I ran a quick test with something like this, and everything worked as expected $opts = array(‘http’ => array(‘header’=> ‘Cookie: ‘ . $_SERVER[‘HTTP_COOKIE’].”\r\n”)); $context = stream_context_create($opts); $contents = … Read more

Weak typing in PHP: why use isset at all?

if ($tx) This code will evaluate to false for any of the following conditions: unset($tx); // not set, will also produce E_WARNING $tx = null; $tx = 0; $tx = ‘0’; $tx = false; $tx = array(); The code below will only evaluate to false under the following conditions: if (isset($tx)) // False under following … Read more

PHP/GD – transparent background

imagecolortransparent is probably not what you want here if you’re merging images, as single-colour transparency is nasty. Instead, try it with a transparent fill mask like so: <?php $image = imagecreatetruecolor(100, 100); // Transparent Background imagealphablending($image, false); $transparency = imagecolorallocatealpha($image, 0, 0, 0, 127); imagefill($image, 0, 0, $transparency); imagesavealpha($image, true); // Drawing over $black = … Read more

Best way to internationalize simple PHP website

Although ext/gettext and ext/intl are both related to i18 (internationalization), gettext deals with translation while intl deals with internationalizing things like number and date display, sorting orders and transliteration. So you’d actually need both for a complete i18-solution. Depending on your needs you may come up with an home-brew solution relying on the extensions mentioned … Read more

Laravel 5 get view name

Update your AppServiceProvider by adding a view composer to the boot method and using ‘*’ to share it with all views: <?php namespace App\Providers; use Illuminate\Support\ServiceProvider; class AppServiceProvider extends ServiceProvider { /** * Bootstrap any application services. * * @return void */ public function boot() { view()->composer(‘*’, function($view){ $view_name = str_replace(‘.’, ‘-‘, $view->getName()); view()->share(‘view_name’, $view_name); … Read more

php default arguments [duplicate]

Passing null or “” for a parameter you don’t want to specify still results in those nulls and empty strings being passed to the function. The only time the default value for a parameter is used is if the parameter is NOT SET ALL in the calling code. example(‘a’) will let args #2 and #3 … Read more