/*
URL을 파싱하여 배열로 반환
parse_url
array = parse_url(string_url)
http://php.net/manual/en/function.parse-url.php
*/
$url = "http://php.net:8080/manual/en/function.parse-url.php?id=value1&pw=value2#anchor";
print_r(parse_url($url));
echo parse_url($url, PHP_URL_PATH);
$ftp = parse_url("ftp://id:password@ftp.php.net");
print_r($ftp);
/*
URL을 통해 전송되는 문자열을 인코딩
urlencode
string = urlencode(string_str)
http://php.net/manual/en/function.urlencode.php
*/
$url1 = "click";
$url2 = "click";
echo $url1;
echo $url2;
/*
인코딩된 문자열을 디코딩
urldecode
string = urldecode(string_str)
http://php.net/manual/en/function.urldecode.php
*/
$query = "id=A&password=B+and+C";
foreach (explode('&', $query) as $chunk) {
$param = explode("=", $chunk);
if ($param) {
printf("Value for parameter \"%s\" is \"%s\"
\n", urldecode($param[0]), urldecode($param[1]));
}
}
/*
RFC 1738 규약에 따라 URL을 인코딩
rawurlencode
string = rawurlencode(string_str)
http://php.net/manual/en/function.rawurlencode.php
*/
echo "click";
/*
인코딩된 문자열을 디코딩
rawurldecode
string = rawurldecode(string_str)
http://php.net/manual/en/function.rawurldecode.php
*/
echo rawurldecode('foo%20bar%40baz+apple'); // foo bar@baz
/*
MIME 규약에 따라 BASE64 방식으로 인코딩된 문자열을 반환
base64_encode
string = base64_encode(string_data)
http://php.net/manual/en/function.base64-encode.php
*/
$str = 'This is an encoded string';
echo base64_encode($str);
/*
BASE64 방법으로 인코딩된 문자열을 디코딩하여 문자열을 반환
base64_decode
string = base64_decode(string_data)
http://php.net/manual/en/function.base64-decode.php
*/
$str = 'VGhpcyBpcyBhbiBlbmNvZGVkIHN0cmluZw==';
echo base64_decode($str);
/*
인코딩된 쿼리 문자열을 생성
http_build_query
string = http_build_query(mixed_query_data)
http://php.net/manual/en/function.http-build-query.php
*/
$data = array
(
'a'=>'apple',
'b'=>'banana+',
'c'=>'cherry & cheese',
'd'=>'dog GOD',
'e',
'f',
'g',
'h'=>array
(
'h1'=>'hello',
'h2'=>'hentai',
'h3'=>'hippo'
)
);
echo http_build_query($data);
echo http_build_query($data, 'X');
/*
클라이언트의 요청에 대한 응답으로 서버가 전송하는 헤더정보를 배열로 반환
get_headers
array = get_headers(string_url)
http://php.net/manual/en/function.get-headers.php
*/
$url = "http://php.net";
print_r(get_headers($url));
print_r(get_headers($url,1));
댓글
댓글 쓰기