Guzzle 6: no more json() method for responses

Previously in Guzzle 5.3: $response = $client->get(‘http://httpbin.org/get’); $array = $response->json(); // Yoohoo var_dump($array[0][‘origin’]); I could easily get a PHP array from a JSON response. Now In Guzzle 6, I don’t know how to do. There seems to be no json() method anymore. I (quickly) read the doc from the latest version and don’t found anything … Read more

Amazon S3 – How to fix ‘The request signature we calculated does not match the signature’ error?

I have searched on the web for over two days now, and probably have looked through most of the online documented scenarios and workarounds, but nothing worked for me so far. I am on AWS SDK for PHP V2.8.7 running on PHP 5.3. I am trying to connect to my Amazon S3 bucket with the … Read more

Nullable return types in PHP7

PHP 7 introduces return type declarations. Which means I can now indicate the return value is a certain class, interface, array, callable or one of the newly hintable scalar types, as is possible for function parameters. function returnHello(): string { return ‘hello’; } Often it happens that a value is not always present, and that … Read more

How to delete a file via PHP?

How do I delete a file from my server with PHP if the file is in another directory? Here is my page layout: projects/backend/removeProjectData.php (this file deletes all my entries for the database and should also delete the related file) public_files/22.pdf (the place where the file is located.) I’m using the unlink function: unlink(‘../../public_files/’ . … Read more

How to loop through an associative array and get the key? [duplicate]

This question already has answers here: PHP foreach loop key value (4 answers) Closed 2 years ago. My associative array: $arr = array( 1 => “Value1”, 2 => “Value2”, 10 => “Value10” ); Using the following code, $v is filled with $arr‘s values foreach($arr as $v){ echo($v); // Value1, Value2, Value10 } How do I … Read more

Why does the PHP json_encode function convert UTF-8 strings to hexadecimal entities?

I have a PHP script that deals with a wide variety of languages. Unfortunately, whenever I try to use json_encode, any Unicode output is converted to hexadecimal entities. Is this the expected behavior? Is there any way to convert the output to UTF-8 characters? Here’s an example of what I’m seeing: INPUT echo $text; OUTPUT … Read more