-3

I have my seo url such as

http://domain.com/product/export-grade-large-size-3-tier-organizer-shelf-and-non-woven-storage-box-with-cover-21665223

at the tail of string there is a number represented an id, which I need it for DB processing, how can I separate and get the last id? I cannot use explode because it may have long string parameter with 'dash'.

thanks.

kefoseki
  • 71
  • 2
  • 8

1 Answers1

2

You can do this with:

$url = 'http://domain.com/product/export-your-url-with-21665223';
$id = substr($url, strrpos($url, '-') + 1);
echo $id;
Ryan
  • 1,151
  • 5
  • 7