xref: /curl/docs/libcurl/curl_escape.md (revision e3fe0200)
1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: curl_escape
5Section: 3
6Source: libcurl
7See-also:
8  - curl_free (3)
9  - curl_unescape (3)
10Protocol:
11  - All
12---
13
14# NAME
15
16curl_escape - URL encodes the given string
17
18# SYNOPSIS
19
20~~~c
21#include <curl/curl.h>
22
23char *curl_escape(const char *string, int length);
24~~~
25
26# DESCRIPTION
27
28Obsolete function. Use curl_easy_escape(3) instead!
29
30This function converts the given input **string** to a URL encoded string
31and return that as a new allocated string. All input characters that are not
32a-z, A-Z or 0-9 are converted to their "URL escaped" version (**%NN** where
33**NN** is a two-digit hexadecimal number).
34
35If the **length** argument is set to 0, curl_escape(3) uses strlen()
36on **string** to find out the size.
37
38You must curl_free(3) the returned string when you are done with it.
39
40# EXAMPLE
41
42~~~c
43int main(void)
44{
45  char *output = curl_escape("data to convert", 15);
46  if(output) {
47    printf("Encoded: %s\n", output);
48    curl_free(output);
49  }
50}
51~~~
52
53# AVAILABILITY
54
55Since 7.15.4, curl_easy_escape(3) should be used. This function might be
56removed in a future release.
57
58# RETURN VALUE
59
60A pointer to a null-terminated string or NULL if it failed.
61