2

What is the following conversion called? Is there any way to generate this source inside PHP from a textbox I input from and what is this process called?

Original

Title here

Description located here

enter

enter

last text

Source

jobdesc=Title+here%0D%0A%0D%0ADescription+located+here%0D%0A%0D%0Aenter%0D%0A%0D%0Aenter%0D%0A%0D%0Alast+text&curlsubmit=submit

0

2 Answers 2

4

It is URL encoded, and you can use:

$encoded = urlencode($input);

In addition to the URL encoding, your example also has &curlsubmit=submit appended which isn't present in the text.

To get the exact same output:

$output = 'jobdesc=' . urlencode($input) . '&curlsubmit=submit';

URL encoding is a standard format for encoding query strings and form data that is used by all browsers. It prevents special characters such as & from breaking the key-value format of the string.

More info

Sign up to request clarification or add additional context in comments.

1 Comment

Exactly what i needed. Thank you so much. I love your explanation and examples, Thank you.
2

If you have your form method marked as GET and you press submit button then it will appear in your url adress. It is called url encoding.

In php you can change text to such format with urlencode(); function; To decode string encoded with Url encode use urldecode()

Read more about url encoding.

  1. PHP MANUAL
  2. W3S
  3. RFC

More about encoding from RFC

2.1. Percent-Encoding

A percent-encoding mechanism is used to represent a data octet in a component when that octet's corresponding character is outside the allowed set or is being used as a delimiter of, or within, the component. A percent-encoded octet is encoded as a character triplet, consisting of the percent character "%" followed by the two hexadecimal digits representing that octet's numeric value. For example, "%20" is the percent-encoding for the binary octet "00100000" (ABNF: %x20), which in US-ASCII corresponds to the space character (SP). Section 2.4 describes when percent-encoding and decoding is applied.

  pct-encoded = "%" HEXDIG HEXDIG

The uppercase hexadecimal digits 'A' through 'F' are equivalent to the lowercase digits 'a' through 'f', respectively. If two URIs differ only in the case of hexadecimal digits used in percent-encoded octets, they are equivalent. For consistency, URI producers and normalizers should use uppercase hexadecimal digits for all percent- encodings.

1 Comment

Thank you, your explication is definitely helpful in terms of theory. Helped me better understand URL Encoding.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.