title: Add a string before the last slash in other string
body: <p>I've pulled the current URL into a variable. So my url is in variable $url.</p>
  <p>Example of the <code>$url = 'http://domain.test/en/offers/guided-tours/neighbourhoods/academy-traces-of-the-academy-in-antwerp/'</code></p>
  <p>Now I want to add a new variable (<code>$venueSlug</code>) before the last slash. Example of value from that variable <code>$venueSlug = 'antwerp-city-guided'</code>;</p>
  <p>The wanted result would be</p>
  <pre><code>$newUrl = 'http://domain.test/en/offers/guided-tours/neighbourhoods/antwerp-city-guides/academy-traces-of-the-academy-in-antwerp/'
  </code></pre>
  <p>My code looks like this:</p>
  <pre><code>function custom_post_type_link_venue ($urlsub, $post) {
   
          //get venue slug
          $venueSlug = get_post_field( 'post_name', $venueId );
          
          if (!empty($venueSlug)) {
              if (substr_count($urlsub, $replace) == 0) {
                  $urlsub = str_replace($s=strrchr($urlsub, '/'), &quot;'/'$venueSlug.$s&quot;, $urlsub);
                  
              }
  
          }
  
      return $urlsub;
  }
  </code></pre>
  <p>But it adds the new variable before every slash:</p>
  <pre><code>http://'/'.antwerp-city-guides./'/'.antwerp-city-guides./antwerp.test'/'.antwerp-city-guides./en'/'.antwerp-city-guides./offers'/'.antwerp-city-guides./guided-tours'/'.antwerp-city-guides./neighbourhoods'/'.antwerp-city-guides./academy-traces-o…ademy-in-antwerp'/'.antwerp-city-guides./ ‎
  </code></pre>