1. Go to this page and download the library: Download tbolner/flex-php-io library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
tbolner / flex-php-io example snippets
declare(strict_types=1);
namespace MyProject;
use FlexPhpIO\Response;
Response::bufferStart();
Response::HtmlContentType();
echo '<html><body><p>Hello World!</p></body></html>';
declare(strict_types=1);
namespace MyProject;
use FlexPhpIO\Request;
use FlexPhpIO\Response;
try {
Response::bufferStart();
$input_data = Request::getPostedJson();
$message = @trim((string)$input_data["message"]);
if ($message == "") {
throw new \Exception("Missing or invalid 'message' field in input.");
}
Response::printJson([
"status" => "ok",
"message" => $message
]);
} catch (\Exception $ex) {
Response::printJson([
"status" => "error",
"message" => $ex->getMessage();
], 400);
}
declare(strict_types=1);
namespace MyProject\Controller;
use FlexPhpRouter\Router;
use FlexPhpIO\Response;
Router::get(
"items/{id:int}/info",
function (int $id) {
Response::printJson([
"item_id" => $id
]);
}
);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.