"PHP uri template 튜토리얼"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-source +syntaxhighlight))
 
(다른 사용자 한 명의 중간 판 10개는 보이지 않습니다)
2번째 줄: 2번째 줄:


==사전 작업==
==사전 작업==
*[[PECL uri_template 설치]]
*<del>[[PECL uri_template 설치]]</del>
* [[composer uri-template 설치]]


==예시==
==예시 1==
*예제: http://zetawiki.com/php/uri-template/tutorial1.php
<syntaxhighlight lang='php'>
<source lang='php'>
<?php
<?php
include 'vendor/autoload.php';
function uri_template( $temp, $params ) {
return \UriTemplate\UriTemplate::expand($temp, $params);
}
$params = array(
$params = array(
'action' => 'query',
'action' => 'query',
16번째 줄: 21번째 줄:
$temp = 'http://zetawiki.com/w/api.php?action={action}&format={format}&prop={prop}&pageids={pageids}';
$temp = 'http://zetawiki.com/w/api.php?action={action}&format={format}&prop={prop}&pageids={pageids}';
$url = uri_template($temp, $params);
$url = uri_template($temp, $params);
?>
echo $url;
<a href='$temp'><?php echo $temp; ?></a>
# http://zetawiki.com/w/api.php?action=query&format=xml&prop=info&pageids=1309
</source>
</syntaxhighlight>
 
==예시 2==
<syntaxhighlight lang='php'>
$params = array(
'namespace' => 'wiki',
'title' => '고양이'
);
$url = uri_template('http://zetawiki.com/{namespace}/{title}', $params);
echo $url;
# http://zetawiki.com/wiki/%EA%B3%A0%EC%96%91%EC%9D%B4
</syntaxhighlight>


==같이 보기==
==같이 보기==
*[[PHP uri template 튜토리얼 2]]
*[[PHP uri_template]]
*[[PHP uri_template]]


[[분류: PHP]]
[[분류: PHP]]
[[분류: 튜토리얼]]

2020년 11월 2일 (월) 02:35 기준 최신판

PHP uri_template 튜토리얼

1 사전 작업[ | ]

2 예시 1[ | ]

<?php
include 'vendor/autoload.php';
function uri_template( $temp, $params ) {
	return \UriTemplate\UriTemplate::expand($temp, $params);
}

$params = array(
	'action' => 'query',
	'format' => 'xml',
	'prop' => 'info',
	'pageids' => 1309
);
$temp = 'http://zetawiki.com/w/api.php?action={action}&format={format}&prop={prop}&pageids={pageids}';
$url = uri_template($temp, $params);
echo $url;
# http://zetawiki.com/w/api.php?action=query&format=xml&prop=info&pageids=1309

3 예시 2[ | ]

$params = array(
	'namespace' => 'wiki',
	'title' => '고양이'
);
$url = uri_template('http://zetawiki.com/{namespace}/{title}', $params);
echo $url;
# http://zetawiki.com/wiki/%EA%B3%A0%EC%96%91%EC%9D%B4

4 같이 보기[ | ]

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