title: Recursive function to call itself untill it returns a value
body: <p>I am trying to check if a string contains something between <code>{}</code> and if it does replace it with what it relates too the issue I am having with this is calling it to itself</p>
  
  <p>For reference lets assume we have a string <code>https://technologyforthefuture.org/open-doors-challenge/?modalActive=true&amp;video_id={user_video_id}&amp;key-={user_affiliate_id}</code></p>
  
  <p>We pass this string into the below function <code>ParseShortcodes()</code></p>
  
  <p>What will happen currently is <code>{user_video_id}</code> will be noticed and replaced and then that will be the end of the loop and nothing will be returned because the code is waiting for <code>$short</code> to be empty to return template</p>
  
  <p>I had though about calling <code>ParseShortcodes()</code> within itself but I dont think this is the right way to do this there must be some better way</p>
  
  <pre class="lang-php prettyprint-override"><code>function get_string_between($string, $start, $end){
              $string = ' ' . $string;
              $ini = strpos($string, $start);
              if ($ini == 0) return '';
              $ini += strlen($start);
              $len = strpos($string, $end, $ini) - $ini;
              return substr($string, $ini, $len);
          }
  
          function ParseShortcodes($template,$post_id){
              $short = get_string_between($template,"{","}");
  
              if($short == "user_affiliate_id"){
                  global $wpdb;
  
                  $query = $wpdb-&gt;get_row("SELECT * FROM wp_uap_affiliates WHERE uid=3");
  
                  $short = $query-&gt;id;
  
                  $template = str_replace("{user_affiliate_id}",$short,$template);
              }else if($short == "user_video_id"){
                  $template = str_replace("{user_video_id}",$post_id,$template);
              }else if(empty($short)){
                  return $template;
              }
          }
  </code></pre>