PHP Classes

File: classes/TBencodeHandler/example3.php

Recommend this page to a friend!
  Classes of ASCOOS CMS   AFW Examples   classes/TBencodeHandler/example3.php   Download  
File: classes/TBencodeHandler/example3.php
Role: Example script
Content type: text/plain
Description: Example 3: Dictionary compatible with BitTorrent
Class: AFW Examples
Examples and tests of usage of Ascoos Framework
Author: By
Last change:
Date: 6 days ago
Size: 712 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 = ["publisher" => "Bob", "length" => 12345, "files" => ["file1.txt", "file2.txt"]];
$encoded = $bencode->encode($data);
$decoded = $bencode->decode($encoded);

echo
"Encoded: $encoded\n"; // PRINT: "d5:filesl9:file1.txt9:file2.txte6:lengthi12345e9:publisher3:Bobe" (??????? ????????????)
var_dump($decoded); // PRINT: array(3) { ["files"]=> array(2) { [0]=> string(9) "file1.txt" [1]=> string(9) "file2.txt" } ["length"]=> int(12345) ["publisher"]=> string(3) "Bob" }
?>