Skip to content

Instantly share code, notes, and snippets.

@mriso79
Created December 27, 2018 22:12
Show Gist options
  • Save mriso79/c1e0eca18c3e44d61e3f5986c443bac6 to your computer and use it in GitHub Desktop.
Save mriso79/c1e0eca18c3e44d61e3f5986c443bac6 to your computer and use it in GitHub Desktop.
A decent JSON response with Charset UTF-8 with PHP
<?php
namespace lib\http;
class JsonResponse {
function __construct(){}
public static function simpleJsonResponse($object){
header('Content-Type: application/json; charset=utf-8');
echo json_encode($object, JSON_FORCE_OBJECT);
}
}
@mriso79
Copy link
Author

mriso79 commented Dec 27, 2018

The namespace refers to one of my projects so you can remove or customize according to your own project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment