Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

--TEST-- uri_template() expansion 3 - URL fragment tests --FILE-- <?php $data = array( '..

Decoded Output download

--TEST--
uri_template() expansion 3 - URL fragment tests
--FILE--
<?php
$data = array(
  'count'      => array("one", "two", "three"),
  'dom'        => array("example", "com"),
  'dub'        => "me/too",
  'hello'      => "Hello World!",
  'half'       => "50%",
  'var'        => "value",
  'who'        => "fred",
  'base'       => "http://example.com/home/",
  'path'       => "/foo/bar",
  'list'       => array("red", "green", "blue"),
  'keys'       => array(
    "semi"  => ";",
    "dot"   => ".",
    "comma" => ",",
  ),
  'v'          => "6",
  'x'          => "1024",
  'y'          => "768",
  'empty'      => "",
  'empty_keys' => array(),
  'undef'      => null,
);

$templates = array(
  "{#var}"         => "#value",
  "{#hello}"       => "#Hello%20World!",
  "{#half}"        => "#50%25",
  "foo{#empty}"    => "foo#",
  "foo{#undef}"    => "foo",
  "{#x,hello,y}"   => "#1024,Hello%20World!,768",
  "{#path,x}/here" => "#/foo/bar,1024/here",
  "{#path:6}/here" => "#/foo/b/here",
  "{#list}"        => "#red,green,blue",
  "{#list*}"       => "#red,green,blue",
  "{#keys}"        => "#semi,;,dot,.,comma,,",
  "{#keys*}"       => "#semi=;,dot=.,comma=,"
);

$out = array();

foreach ($templates as $tpl => $expect) {
  $result = NULL;
  uri_template($tpl, $data, $result);
  unset($result['expressions']);
  $out[] = $result;
}

var_dump($out);
?>
--EXPECT--
array(12) {
  [0]=>
  array(2) {
    ["result"]=>
    string(6) "#value"
    ["state"]=>
    int(0)
  }
  [1]=>
  array(2) {
    ["result"]=>
    string(15) "#Hello%20World!"
    ["state"]=>
    int(0)
  }
  [2]=>
  array(2) {
    ["result"]=>
    string(6) "#50%25"
    ["state"]=>
    int(0)
  }
  [3]=>
  array(2) {
    ["result"]=>
    string(4) "foo#"
    ["state"]=>
    int(0)
  }
  [4]=>
  array(2) {
    ["result"]=>
    string(3) "foo"
    ["state"]=>
    int(0)
  }
  [5]=>
  array(2) {
    ["result"]=>
    string(24) "#1024,Hello%20World!,768"
    ["state"]=>
    int(0)
  }
  [6]=>
  array(2) {
    ["result"]=>
    string(19) "#/foo/bar,1024/here"
    ["state"]=>
    int(0)
  }
  [7]=>
  array(2) {
    ["result"]=>
    string(12) "#/foo/b/here"
    ["state"]=>
    int(0)
  }
  [8]=>
  array(2) {
    ["result"]=>
    string(15) "#red,green,blue"
    ["state"]=>
    int(0)
  }
  [9]=>
  array(2) {
    ["result"]=>
    string(15) "#red,green,blue"
    ["state"]=>
    int(0)
  }
  [10]=>
  array(2) {
    ["result"]=>
    string(21) "#semi,;,dot,.,comma,,"
    ["state"]=>
    int(0)
  }
  [11]=>
  array(2) {
    ["result"]=>
    string(21) "#semi=;,dot=.,comma=,"
    ["state"]=>
    int(0)
  }
}

Did this file decode correctly?

Original Code

--TEST--
uri_template() expansion 3 - URL fragment tests
--FILE--
<?php
$data = array(
  'count'      => array("one", "two", "three"),
  'dom'        => array("example", "com"),
  'dub'        => "me/too",
  'hello'      => "Hello World!",
  'half'       => "50%",
  'var'        => "value",
  'who'        => "fred",
  'base'       => "http://example.com/home/",
  'path'       => "/foo/bar",
  'list'       => array("red", "green", "blue"),
  'keys'       => array(
    "semi"  => ";",
    "dot"   => ".",
    "comma" => ",",
  ),
  'v'          => "6",
  'x'          => "1024",
  'y'          => "768",
  'empty'      => "",
  'empty_keys' => array(),
  'undef'      => null,
);

$templates = array(
  "{#var}"         => "#value",
  "{#hello}"       => "#Hello%20World!",
  "{#half}"        => "#50%25",
  "foo{#empty}"    => "foo#",
  "foo{#undef}"    => "foo",
  "{#x,hello,y}"   => "#1024,Hello%20World!,768",
  "{#path,x}/here" => "#/foo/bar,1024/here",
  "{#path:6}/here" => "#/foo/b/here",
  "{#list}"        => "#red,green,blue",
  "{#list*}"       => "#red,green,blue",
  "{#keys}"        => "#semi,;,dot,.,comma,,",
  "{#keys*}"       => "#semi=;,dot=.,comma=,"
);

$out = array();

foreach ($templates as $tpl => $expect) {
  $result = NULL;
  uri_template($tpl, $data, $result);
  unset($result['expressions']);
  $out[] = $result;
}

var_dump($out);
?>
--EXPECT--
array(12) {
  [0]=>
  array(2) {
    ["result"]=>
    string(6) "#value"
    ["state"]=>
    int(0)
  }
  [1]=>
  array(2) {
    ["result"]=>
    string(15) "#Hello%20World!"
    ["state"]=>
    int(0)
  }
  [2]=>
  array(2) {
    ["result"]=>
    string(6) "#50%25"
    ["state"]=>
    int(0)
  }
  [3]=>
  array(2) {
    ["result"]=>
    string(4) "foo#"
    ["state"]=>
    int(0)
  }
  [4]=>
  array(2) {
    ["result"]=>
    string(3) "foo"
    ["state"]=>
    int(0)
  }
  [5]=>
  array(2) {
    ["result"]=>
    string(24) "#1024,Hello%20World!,768"
    ["state"]=>
    int(0)
  }
  [6]=>
  array(2) {
    ["result"]=>
    string(19) "#/foo/bar,1024/here"
    ["state"]=>
    int(0)
  }
  [7]=>
  array(2) {
    ["result"]=>
    string(12) "#/foo/b/here"
    ["state"]=>
    int(0)
  }
  [8]=>
  array(2) {
    ["result"]=>
    string(15) "#red,green,blue"
    ["state"]=>
    int(0)
  }
  [9]=>
  array(2) {
    ["result"]=>
    string(15) "#red,green,blue"
    ["state"]=>
    int(0)
  }
  [10]=>
  array(2) {
    ["result"]=>
    string(21) "#semi,;,dot,.,comma,,"
    ["state"]=>
    int(0)
  }
  [11]=>
  array(2) {
    ["result"]=>
    string(21) "#semi=;,dot=.,comma=,"
    ["state"]=>
    int(0)
  }
}

Function Calls

uri_template 1

Variables

$out []
$tpl #value
$data [{'key': 'count', 'value': [{'key': 0, 'value': 'one'}, {'key': 1, 'value': 'two'}, {'key': 2, 'value': 'three'}]}, {'key': 'dom', 'value': [{'key': 0, 'value': 'example'}, {'key': 1, 'value': 'com'}]}, {'key': 'dub', 'value': 'me/too'}, {'key': 'hello', 'value': 'Hello World!'}, {'key': 'half', 'value': '50%'}, {'key': 'var', 'value': 'value'}, {'key': 'who', 'value': 'fred'}, {'key': 'base', 'value': 'http://example.com/home/'}, {'key': 'path', 'value': '/foo/bar'}, {'key': 'list', 'value': [{'key': 0, 'value': 'red'}, {'key': 1, 'value': 'green'}, {'key': 2, 'value': 'blue'}]}, {'key': 'keys', 'value': [{'key': 'semi', 'value': ';'}, {'key': 'dot', 'value': '.'}, {'key': 'comma', 'value': ','}]}, {'key': 'v', 'value': '6'}, {'key': 'x', 'value': '1024'}, {'key': 'y', 'value': '768'}, {'key': 'empty', 'value': ''}, {'key': 'empty_keys', 'value': []}, {'key': 'undef', 'value': 0}]
$expect #value
$result 0
$templates [{'key': '{#var}', 'value': '#value'}, {'key': '{#hello}', 'value': '#Hello%20World!'}, {'key': '{#half}', 'value': '#50%25'}, {'key': 'foo{#empty}', 'value': 'foo#'}, {'key': 'foo{#undef}', 'value': 'foo'}, {'key': '{#x,hello,y}', 'value': '#1024,Hello%20World!,768'}, {'key': '{#path,x}/here', 'value': '#/foo/bar,1024/here'}, {'key': '{#path:6}/here', 'value': '#/foo/b/here'}, {'key': '{#list}', 'value': '#red,green,blue'}, {'key': '{#list*}', 'value': '#red,green,blue'}, {'key': '{#keys}', 'value': '#semi,;,dot,.,comma,,'}, {'key': '{#keys*}', 'value': '#semi=;,dot=.,comma=,'}]

Stats

MD5 9c7ea723f901e659c7949d873ba2be9a
Eval Count 0
Decode Time 92 ms