Search value within Google url

Asked

Viewed 45 times

1

I would like to know how to search and make appear only the values of the URL of Google video, seeking a specific value. In this case I have this code below, with everything not getting the value 0B7fH_c8_hjWVY1pQQVc3dGgxOWs between the /d/ and the /preview.

How can I resolve this so that the result of The item value is 0B7fH_c8_hjWVY1pQQVc3dGgxOWs:

<?php // Retorna um valor na posição 2 pegando o dominio do item como base pra retirar o ID
function buscarID ($urlGeral, $dominio) {
preg_match("/^.*($dominio\/)(\d+)-*/", $urlGeral, $valores);
return $valores[2];
}

echo 'O valor do item e '.buscarID('https://docs.google.com/file/d/0B7fH_c8_hjWVY1pQQVc3dGgxOWs/preview', "docs.google.com"); ?>

1 answer

1


Try using regex like this:

preg_match('file\/d\/(.*?)\/preview', $urlGeral, $valores);

Also, remember that using the "$variavel" PHP, PHP puts exactly what the variable has into the string. That is, your Regex would look like this:

^.*(docs.google.com\/)(\d+)-*

But that doesn’t add up to anything $urlGeral.

A great tool to test regex is regex., that shows you exactly what is being found.

Browser other questions tagged

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