{"id":3631,"date":"2022-11-10T08:46:35","date_gmt":"2022-11-10T08:46:35","guid":{"rendered":"https:\/\/info.documotor.com\/?page_id=3631"},"modified":"2023-03-22T11:57:29","modified_gmt":"2023-03-22T11:57:29","slug":"split_on","status":"publish","type":"page","link":"https:\/\/info.documotor.com\/?page_id=3631","title":{"rendered":"Split_on"},"content":{"rendered":"\n<p>The function <code>split_on<\/code> can be used to split a string into an array of strings where it is split on defined string separators. <\/p>\n\n\n\n<h3>Syntax<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">array split_on(string $input, boolean $ignore_empty, args[]:string $separators)<\/code><\/pre>\n\n\n\n<p>Splits the $input string into an array of strings where it is split on the given string $separators defined. $ignore_empty defines whether empty strings in the new array should be ignored or not. <\/p>\n\n\n\n<h3>Parameters<\/h3>\n\n\n\n<p><strong>$input:<\/strong> The string that should be split.<br><strong>$ignore_empty:<\/strong> The boolean that defines whether empty strings should be ignored in the array. <br><strong>$separators:<\/strong> A variable number of strings that the $input string should be split on.<\/p>\n\n\n\n<h3>Example<\/h3>\n\n\n\n<pre title=\"Data\" class=\"wp-block-code\"><code lang=\"json\" class=\"language-json\">{\n    \"InputString\": \"This-is--some-text\"\n}<\/code><\/pre>\n\n\n\n<pre title=\"Transformation\" class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">{\n    OutputIgnoreTrue: split_on(InputString, `true`, '-'),\n    OutputIgnoreFalse: split_on(InputString, `false`, '-')\n}<\/code><\/pre>\n\n\n\n<pre title=\"Output\" class=\"wp-block-code\"><code lang=\"json\" class=\"language-json\">{\n    \"OutputIgnoreTrue\": [\"This\", \"is\", \"some\", \"text\"],\n    \"OutputIgnoreFalse\": [\"This\", \"is\", \"\", \"some\", \"text\"]\n}<\/code><\/pre>\n\n\n\n<p>Above examples splits the $input string on the string separator &#8220;-&#8220;. The two outputs shows the difference between having $ignore_empty to <em>true<\/em> or <em>false<\/em>.<br><code>True<\/code> removes the empty strings from the array where <code>false <\/code>keeps the empty strings in the array.<\/p>\n\n\n\n<h3>Notes<\/h3>\n\n\n\n<p><strong>Multiple separators<\/strong><\/p>\n\n\n\n<p>As mentioned in the <em>parameters<\/em> section, the $separators parameter is a variable number of strings. This means that it is possible to define multiple separator strings that the $input string can be split on. <\/p>\n\n\n\n<p><strong>Example<\/strong><\/p>\n\n\n\n<pre title=\"Data\" class=\"wp-block-code\"><code lang=\"json\" class=\"language-json\">{\n    \"MultipleInput\": \"This-is new-text\"\n}<\/code><\/pre>\n\n\n\n<pre title=\"Transformation\" class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">{\n    MultipleSeparators: split_on(MultipleInput, `true`, '-', ' ')\n}<\/code><\/pre>\n\n\n\n<pre title=\"Output\" class=\"wp-block-code\"><code lang=\"json\" class=\"language-json\">{\n    \"MultipleSeparators\": [\"This\", \"is\", \"new\", \"text\"]\n}<\/code><\/pre>\n\n\n\n<p>Above example shows how the MultipleInput string is split on both &#8220;-&#8221; and &#8221; &#8220;.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The function split_on can be used to split a string into an array of strings where it is split on defined string separators. Syntax Splits the $input string into an array of strings where it is split on the given string $separators defined. $ignore_empty defines whether empty strings in the new array should be ignored [&hellip;]<\/p>\n","protected":false},"author":17,"featured_media":0,"parent":271,"menu_order":184,"comment_status":"closed","ping_status":"closed","template":"","meta":[],"_links":{"self":[{"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages\/3631"}],"collection":[{"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/users\/17"}],"replies":[{"embeddable":true,"href":"https:\/\/info.documotor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3631"}],"version-history":[{"count":23,"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages\/3631\/revisions"}],"predecessor-version":[{"id":3813,"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages\/3631\/revisions\/3813"}],"up":[{"embeddable":true,"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages\/271"}],"wp:attachment":[{"href":"https:\/\/info.documotor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3631"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}