{"id":1330,"date":"2026-01-13T09:25:55","date_gmt":"2026-01-13T09:25:55","guid":{"rendered":"https:\/\/monkey.ploogie.co.uk\/?page_id=1330"},"modified":"2026-01-13T09:52:35","modified_gmt":"2026-01-13T09:52:35","slug":"mwnci-tr-function","status":"publish","type":"page","link":"https:\/\/monkey.ploogie.co.uk\/index.php\/mwnci-tr-function\/","title":{"rendered":"Mwnci tr() Function"},"content":{"rendered":"<h2>Syntax<\/h2>\n<p>tr<strong>(<em>string1<\/em>,<em>string2<\/em>, <em>string3<\/em>)<\/strong><\/p>\n<h2>Description<\/h2>\n<p>The <i>tr()<\/i> function substitutes characters in <em>string1<\/em> using <em>string2<\/em> as the list of characters to replace, with <em>string3<\/em> being used as the list to use as the replacements.<br \/>\nThe characters in <em>string2<\/em> are translated into the characters in <em>string3<\/em> where the first character in <em>string2<\/em> is translated into the first character in <em>string3<\/em> and so on.  If <em>string2<\/em> is longer than <em>string3<\/em>, the last character found in <em>string3<\/em> is duplicated until <em>string2<\/em> is exhausted.<\/p>\n<p>Sequences can contain:<\/p>\n<pre>\r\n<strong>[:alnum:]<\/strong>   all letters an digits\r\n<strong>[:alpha:]<\/strong>   all letters\r\n<strong>[:blank:]<\/strong>   all horizontal whitespace\r\n<strong>[:digit:]<\/strong>   all digits\r\n<strong>[:graph:]<\/strong>   all printable characters, not including space\r\n<strong>[:lower:]<\/strong>   all lower case letters\r\n<strong>[:punct:]<\/strong>   all punctuation characters\r\n<strong>[:space:]<\/strong>   all horizontal or vertical whitespace\r\n<strong>[:upper:]<\/strong>   all upper case letters\r\n<strong>[:word:]<\/strong>    all valid characters for a word (digit, upper, lower, \"_\")\r\n<strong>[:xdigit:]<\/strong>  all hexadecimal digits (digit, A-F, a-f)\r\n<\/pre>\n<h2>Example<\/h2>\n<pre>include(\"main\")\r\na=\"This is a string\"\r\na=tr(a, \"si\", \"SI\")\r\nprintln(a)\r\na=tr(a, \"[:upper:]\", \"[:lower:]\")\r\nprintln(a)\r\na=\"This contains 3 numbers, not including the original number 3, I.e  2, 4, 7\"\r\na=tr(a, \"T[:digit:]\", \"t+\")\r\nprintln(a)\r\n\r\n\r\nThIS IS a StrIng\r\nthis is a string\r\nthis contains + numbers, not including the original number +, I.e  +, +, +\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Syntax tr(string1,string2, string3) Description The tr() function substitutes characters in string1 using string2 as the list of characters to replace, with string3 being used as the list to use as the replacements. The characters in string2 are translated into the characters in string3 where the first character in string2 is translated into the first character &hellip; <a href=\"https:\/\/monkey.ploogie.co.uk\/index.php\/mwnci-tr-function\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Mwnci tr() Function&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1330","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/pages\/1330","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/comments?post=1330"}],"version-history":[{"count":6,"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/pages\/1330\/revisions"}],"predecessor-version":[{"id":1336,"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/pages\/1330\/revisions\/1336"}],"wp:attachment":[{"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/media?parent=1330"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}