Special
The Pebble\Special
class if used to encode HTML entities. It is just a wrapper around htmlspecialchars
that encodes arrays for easy use in templates.
examples/special/index.php ->
<?php
require_once "../../vendor/autoload.php";
use Pebble\Special;
// Encode a single string
echo Special::encodeStr('<p>This is a test</p>') . "\n";
// -> <p>This is a test</p>
// Encode an array.
// It will work recursively if the array contains other arrays
$ary_encoded = Special::encodeAry([
'<p>This is a test</p>',
0.99,
true,
'ary' => ['New array <p>Test</p>'],
new stdClass(),
]);
// This string is encoded
// The float is converted to a string
// The boolean is left as it is
// The array is encoded
// The object is left as it is
echo "<pre>";
var_dump($ary_encoded);
echo "</pre>";
// ->
// array(5) {
// [0]=>
// string(33) "<p>This is a test</p>"
// [1]=>
// string(4) "0.99"
// [2]=>
// bool(true)
// ["ary"]=>
// array(1) {
// [0]=>
// string(33) "New array <p>Test</p>"
// }
// [3]=>
// object(stdClass)#3 (0) {
// }
// }
You may run the example using the following command:
php -S localhost:8000 -t examples/special
And then visit http://localhost:8000/