PHPKIT
PHPKIT is a versatile toolkit designed to simplify various tasks in PHP. It provides a set of classes and functions to handle JSON files, print arrays or strings, read and write files, and execute JavaScript code from PHP. Below are the key components of PHPKIT and examples of how to use them.
Namespace
The script resides in the namespace:
use PHPKIT;
JSON
The json class allows you to work with JSON files.
$json = new json($filename);
$json->get("projectName"); // Retrieve the value for the key "projectName"
$json->getall(); // Retrieve the entire JSON array
Printt
The printt function prints arrays or strings.
$array = [
"name" => "Tom"
];
$string = "hello world";
printt($array); // Print the array
printt($string); // Print the string
// or
p($string); // Print the string using the shorthand function
Open
The Open class allows you to read and write files.
Read a file
printt(new Open($filename)->read()); // Read and print the file content
Write a file
$string = "hello world";
new Open($filename)->write($string); // Write the string to the file
Open JSON
Read a JSON file
printt(new Open($filename)->json()); // Read and print the JSON file content
Write a JSON file
$array = [
"name" => "Mari"
];
new Open($filename)->json($array); // Write the array to the JSON file
reloadjs
The reloadjs function reloads the page using JavaScript.
reloadjs(); // Outputs: <script>window.location.reload();</script>
JS
The js function allows you to execute JavaScript code from PHP.
js("console.log('Hello World!')"); // Outputs: "<script>console.log('Hello World!')</script>"