-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_Data.php
More file actions
44 lines (37 loc) · 1.63 KB
/
Copy pathtest_Data.php
File metadata and controls
44 lines (37 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php // Proinf.net — 2017
require_once "Data.php";
header("Content-Type: text/plain");
echo "Test Data";
function output($title, $input, $output) {
$title = "=== $title ";
$line = str_repeat("=", 50 - strlen($title));
$line2 = str_repeat('-', 50);
echo "\n\n$title$line\n";
print_r($input);
echo "\n$line2\n";
print_r($output);
}
require_once "FormatJSON.php";
$encoded = '{ "uno":["dos", "tres"], "cuatro":"cinco" }';
$decoded = array( 'uno'=> array("dos", "tres"), 'cuatro'=>"cinco" );
$data = new Data(new FormatJSON());
$data->setText($encoded); output("JSON decoded", $encoded, $data->getData());
$data->setData($decoded); output("JSON encoded", $decoded, $data->getText());
require_once "FormatXML.php";
$encoded = '<uno dos="tres"><cuatro>cinco</cuatro></uno>';
$decoded = array('uno'=>"dos", 'tres'=>"cuatro");
$data->setFormat(new FormatXML());
$data->setText($encoded); output("XML decoded", $encoded, $data->getData());
$data->setData($decoded); output("XML encoded", $decoded, $data->getText());
require_once "FormatURL.php";
$encoded = 'first=value&arr[]=foo+bar&arr[]=baz';
$decoded = array('foo'=>'bar', 'bar'=>array('var'=> 'foo'));
$data->setFormat(new FormatURL());
$data->setText($encoded); output("URL decoded", $encoded, $data->getData());
$data->setData($decoded); output("URL encoded", $decoded, $data->getText());
require_once "FormatText.php";
$encoded = "uno\ndos";
$decoded = array("uno", "dos");
$data->setFormat(new FormatText());
$data->setText($encoded); output("TEXT decoded", $encoded, $data->getData());
$data->setData($decoded); output("TEXT encoded", $decoded, $data->getText());