• I have custom field where I store urls to related posts I’ve made on another site. The format of the url is https://username.site.com/123456.html. I need to be able to grab just the 123456 part of the url so I can configure some links directly to the edit page of those related posts. Any suggestions?

Viewing 1 replies (of 1 total)
  • Hi,
    Here is how you can do it:

    $str = 'https://username.site.com/123456.html';
    $parts = explode( '/', $str );
    $last_part = end( $parts );
    $code = substr($code, 0, -5);

    This splits the string at the slashes, takes the last part, and removes the 5 last characters from it.
    Hope that helps.

Viewing 1 replies (of 1 total)
  • The topic ‘Trim string containing url down to just one part of url’ is closed to new replies.