PHP Classes

File: classes/TBencodeHandler/example2.php

Recommend this page to a friend!
  Classes of ASCOOS CMS   AFW Examples   classes/TBencodeHandler/example2.php   Download  
File: classes/TBencodeHandler/example2.php
Role: Example script
Content type: text/plain
Description: Example 2: List of mixed data
Class: AFW Examples
Examples and tests of usage of Ascoos Framework
Author: By
Last change:
Date: 10 days ago
Size: 541 bytes
 

Contents

Class file image Download
<?php
global $afw_path; // ASCOOS FRAMEWORK PATH

require_once $afw_path."/extras/encoders/bencode.php";

use
ASCOOS\FRAMEWORK\Extras\Encoders\Bencode\TBencodeHandler;

$bencode = new TBencodeHandler();
$data = ["hello", 42, ["world", -10]];
$encoded = $bencode->encode($data);
$decoded = $bencode->decode($encoded);

echo
"Encoded: $encoded\n"; // PRINT: "l5:helloi42el5:worldi-10eee"
var_dump($decoded); // PRINT: array(3) { [0]=> string(5) "hello" [1]=> int(42) [2]=> array(2) { [0]=> string(5) "world" [1]=> int(-10) } }
?>