-3

I have a bunch of URL's like this. I need to get the thread id which is located between "." and "/" without getting the post number on the end of the URL.

https://www.internetforum.com/thread-title-here.111111/#post-22222222

I'd like regex to get 111111 in this example.

Can anyone help? I can't do this for the life of, I've got no issues with getting digits between two strings but I'm struggling as it's symbols here and not characters...

Thanks in advance.

Ste Hughes
  • 19
  • 1
  • 5

3 Answers3

1

You can use the following code:

<?php

    $url = "https://www.internetforum.com/thread-title-here.111111/#post-22222222";

    preg_match("/\.([0-9]+)\//", $url, $match);

    if($match){
        echo $match[1]; // prints out 111111
    }


    ?>
Željko Krnjić
  • 2,356
  • 2
  • 17
  • 24
0

Could do something like so,

$str = 'https://www.internetforum.com/thread-title-here.111111/#post-22222222';
preg_match('/internetforum.com\/.*?\.(.*?)\/.*/',$str,$matches);
echo $matches[1];
zrinath
  • 106
  • 4
0

Try without regex for example:

$s = 'https://www.internetforum.com/thread-title-here.111111/#post-22222222';
echo $o = explode("/",end(explode(".", $s)))[0];