PHP uri template

Jmnote (토론 | 기여)님의 2015년 6월 23일 (화) 09:30 판 (→‎개요)

1 개요

PHP uri_template
PECL uri_template

2 예시

<?php
require_once "URI/Template.php";

$values = array("a" => "foo", "b" => "bar", "data" => "10,20,30",
                "points" => array(10, 20, 30), "list0" => array(),
                "str0" => "", "reserved" => ":/?#[]@!$&'()*+,;=",
                "a_b" => "baz");

$t = new URI_Template("/{-append|/|a}{-opt|data|points}{-neg|@|a}{-prefix|#|b}");
echo $t->substitute($values); /* /foo/data#bar */

$t = new URI_Template("relative/{reserved}/");
echo $t->substitute($values); /* relative/%3A%2F%3F%23%5B%5D%40%21%24%26%27%28%29%2A%2B%2C%3B%3D/ */

$t = new URI_Template("http://example.org/{foo=%25}/");
echo $t->substitute($values); /* http://example.org/%25/ */

$t = new URI_Template("http://example.org/?{-join|&|a,data}");
echo $t->substitute($values); /* http://example.org/?a=foo&data=10%2C20%2C30 */

$t = new URI_Template("http://example.org/?d={-listjoin|,|points}&{-join|&|a,b}");
echo $t->substitute($values); /* http://example.org/?d=10,20,30&a=foo&b=bar */

$t = new URI_Template("http://example.org/?d={-listjoin|,|list0}&{-join|&|foo}");
echo $t->substitute(array()); /* http://example.org/?d=& */

$t = new URI_Template("http://example.org/?d={-listjoin|&d=|points}");
echo $t->substitute($values); /* http://example.org/?d=10&d=20&d=30 */

$t = new URI_Template("http://example.org/{a}{b}/{a_b}");
echo $t->substitute($values); /* http://example.org/foobar/baz */

$t = new URI_Template("http://example.org/{a}{-prefix|/-/|a}/");
echo $t->substitute($values); /* http://example.org/foo/-/foo/ */

3 같이 보기

4 참고 자료

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}