Taking numeric value of Uol URL

Asked

Viewed 44 times

1

I wonder how I can use php to get only the numerical value of this UOL image url http://thumb.mais.uol.com.br/15516553-medium.jpg?ver=1 in this case only the 15516553 and highlight all the rest being that need to always take the numerical value always in the same position between / and -medium.

1 answer

2


You can use regex for this, example:

$url = 'http://thumb.mais.uol.com.br/15516553-medium.jpg?ver=1';
preg_match("/^.*(uol.com.br\/)(\d+)-*/", $url, $valores);

echo $valores[2]; // seu id ficará na posição [2]

Exit

15516553

Ideone Exemplo

Analysis of the Regex

  • Grateful for the help

Browser other questions tagged

You are not signed in. Login or sign up in order to post.