라이브러리

[PHP] curl_escape - URL은 주어진 문자열을 인코딩합니다.




PHP에서 Curl_escape


PHP의 `curl_escape` 함수는 URL 인코딩을 위한 함수입니다. 이 함수는 URL 에 포함된 문자를 안전하게 인코딩하여 URL 에 포함할 수 있도록 도와줍니다.

# 사용법


`curl_escape` 함수는 두 개의 매개변수를 받습니다.

* `$string`: 인코딩할 문자열
* `$escape_char`: 인코딩할 문자열의 시작 문자 (기본값은 `%`)

# 예제


#hostingforum.kr
php

// 예제 1: 기본 사용법

$url = 'http://example.com/path?query=Hello, World!';

$escaped_url = curl_escape($url);

echo $escaped_url; // http%3A%2F%2Fexample.com%2Fpath%3Fquery%3DHello%2C%20World%21



// 예제 2: escape_char 사용법

$url = 'http://example.com/path?query=Hello, World!';

$escaped_url = curl_escape($url, '+');

echo $escaped_url; // http://example.com/path?query=Hello,+World!



// 예제 3: escape_char 사용법 (URL 인코딩)

$url = 'http://example.com/path?query=Hello, World!';

$escaped_url = curl_escape($url, '%2B');

echo $escaped_url; // http://example.com/path?query=Hello,+World!



# 참고


`curl_escape` 함수는 PHP 4.x 에서 사용할 수 있는 함수입니다. PHP 5.x 부터는 `rawurlencode` 함수를 사용하여 URL 인코딩을 할 수 있습니다.

#hostingforum.kr
php

$url = 'http://example.com/path?query=Hello, World!';

$escaped_url = rawurlencode($url);

echo $escaped_url; // http%3A%2F%2Fexample.com%2Fpath%3Fquery%3DHello%2C%20World%21



# 결론


`curl_escape` 함수는 URL 인코딩을 위한 함수로, URL 에 포함된 문자를 안전하게 인코딩하여 URL 에 포함할 수 있도록 도와줍니다. 이 함수는 PHP 4.x 에서 사용할 수 있는 함수이며, PHP 5.x 부터는 `rawurlencode` 함수를 사용하여 URL 인코딩을 할 수 있습니다.
  • profile_image
    나우호스팅 @pcs8404 

    호스팅포럼 화이팅!

    댓글목록

    등록된 댓글이 없습니다.

  • 전체 8,985건 / 567 페이지

검색

게시물 검색