{"id":2626,"date":"2017-08-01T00:01:03","date_gmt":"2017-08-01T07:01:03","guid":{"rendered":"http:\/\/c-for-dummies.com\/blog\/?p=2626"},"modified":"2017-08-10T07:55:19","modified_gmt":"2017-08-10T14:55:19","slug":"the-url-encoding-filter","status":"publish","type":"post","link":"https:\/\/c-for-dummies.com\/blog\/?p=2626","title":{"rendered":"The URL Encoding Filter"},"content":{"rendered":"<p>URL encoding is a method of translating ASCII codes (not just text or URLs) into what&#8217;s often referred to as <em>percent encoding<\/em>. You&#8217;ve probably seen this format on your web browser&#8217;s address bar or in a search engine&#8217;s text. The encoding format is necessary to preserve the original content as plain text.<br \/>\n<!--more--><br \/>\nFor example, ASCII codes 0 through 31 represent control characters, such as tab, newline, and others. To ensure that those character codes survive transmission over the Internet, URL encoding translates their values into a 2-digit hex string prefixed by the percent sign. So the tab character, ASCII code 8, becomes <code>%08<\/code> when translated. And it&#8217;s translated back to ASCII code 8 when decoded.<\/p>\n<p>With URL encoding\/decoding, not every character is translated into the percent-hex string. Multiple standards exist, but for each one the alphanumeric characters (0-9, A-Z, a-z) are retained. In the HTML 5 standard, the  characters <code>- . _<\/code> and <code>*<\/code> are retained and spaces are converted to the <code>+<\/code> character. Everything else is translated to a two-digit hexadecimal string (upper or lower case) prefixed by a percent sign.<\/p>\n<p>Your task for this month&#8217;s Exercise is to write a URL encoding filter. The filter processes standard input, translating characters to the percent encoding format as necessary, and outputting the result. (Details on writing a filter are presented in my C programming books.)<\/p>\n<p>As an example this page&#8217;s URL is: <code>http:\/\/c-for-dummies.com\/blog\/?p=2626<\/code> When run through the filter, the output is:<\/p>\n<pre><code>http%3A%2F%2Fc-for-dummies.com%2Fblog%2F%3Fp%3D2626<\/code><\/pre>\n<p>Please try this Exercise on your own before you <a href=\"http:\/\/c-for-dummies.com\/blog\/?p=2638\">click here<\/a> to view my solution.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Write a filter to use URL encoding to translate a string of text. <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=2626\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-2626","post","type-post","status-publish","format-standard","hentry","category-exercise"],"_links":{"self":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2626","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2626"}],"version-history":[{"count":4,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2626\/revisions"}],"predecessor-version":[{"id":2657,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2626\/revisions\/2657"}],"wp:attachment":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2626"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2626"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2626"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}