{"id":3682,"date":"2022-11-22T09:30:03","date_gmt":"2022-11-22T09:30:03","guid":{"rendered":"https:\/\/info.documotor.com\/?page_id=3682"},"modified":"2023-03-22T11:57:47","modified_gmt":"2023-03-22T11:57:47","slug":"string_interpolate","status":"publish","type":"page","link":"https:\/\/info.documotor.com\/?page_id=3682","title":{"rendered":"String_interpolate"},"content":{"rendered":"\n<p>String_interpolate injects strings on defined positions in an existing string. <\/p>\n\n\n\n<h3>Syntax<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">string string_interpolate(string $input, array|object $parameters)<\/code><\/pre>\n\n\n\n<p>Inserts the $parameters on positions defined in the $input string. <\/p>\n\n\n\n<h3>Parameters<\/h3>\n\n\n\n<p><strong>$input<\/strong>: The input string where the positions for the $parameters are defined.<br><strong>$parameters:<\/strong> The parameters defined either as an array or as JSON objects that should be inserted in the $input string.<\/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 line-numbers\">{\n    \"ParamArr\":  [\"World\", \"Moon\"]\n}<\/code><\/pre>\n\n\n\n<pre title=\"Transformation\" class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash line-numbers\">{\n    OutputArr: string_interpolate('Hello, {0}! Goodbye, {1}.', ParamArr)\n}<\/code><\/pre>\n\n\n\n<pre title=\"Output\" class=\"wp-block-code\"><code lang=\"json\" class=\"language-json line-numbers\">{\n    \"OutputArr\": \"Hello, World! Goodbye, Moon.\"\n}<\/code><\/pre>\n\n\n\n<p>The above example shows a simple use of the string_interpolate function where the words &#8220;World&#8221; and &#8220;Moon&#8221; gets injected into the input string. In this example an array has been used as $parameters. Here it shows that the array index of the words is inserted in the $input string where {index} has been defined. <\/p>\n\n\n\n<h3>Notes<\/h3>\n\n\n\n<p><strong>Object example<\/strong><\/p>\n\n\n\n<pre title=\"Data\" class=\"wp-block-code\"><code lang=\"json\" class=\"language-json\">{\n    \"ParamObj\": {\n        \"HelloName\": \"World\", \n        \"GoodbyeName\": \"Moon\"\n    }\n}<\/code><\/pre>\n\n\n\n<pre title=\"Transformation\" class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">{\n    OutputObj: string_interpolate('Hello, {HelloName}! Goodbye, {GoodbyeName}.', ParamObj)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"json\" class=\"language-json\">{\n    \"OutputObj\": \"Hello, World! Goodbye, Moon.\"\n}<\/code><\/pre>\n\n\n\n<p>Above example shows how to use the string_interpolate function with a JSON object as $parameter. Here it is shown that the words &#8220;World&#8221; and &#8220;Moon&#8221; gets injected on their respective positions in the $input string where the json keys has been defined like {key}.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>String_interpolate injects strings on defined positions in an existing string. Syntax Inserts the $parameters on positions defined in the $input string. Parameters $input: The input string where the positions for the $parameters are defined.$parameters: The parameters defined either as an array or as JSON objects that should be inserted in the $input string. Example The [&hellip;]<\/p>\n","protected":false},"author":17,"featured_media":0,"parent":271,"menu_order":185,"comment_status":"closed","ping_status":"closed","template":"","meta":[],"_links":{"self":[{"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages\/3682"}],"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=3682"}],"version-history":[{"count":18,"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages\/3682\/revisions"}],"predecessor-version":[{"id":3964,"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages\/3682\/revisions\/3964"}],"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=3682"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}