Search value within url

1

I'd like to know how I can fetch and display only the values from the Google Video URL for a specific value. In this case I have this code below, but everything is not taking the 0B7fH_c8_hjWVY1pQQVc3dGgxOWs value between /d/ and /preview .

How can I resolve this so that the result of The value of the item 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"); ?>
    
asked by anonymous 20.07.2015 / 04:36

1 answer

1

Try to use regex like this:

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

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

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

But this does not hit anything with $urlGeral .

A great tool to test regex is regexr.com , which shows you exactly what is being found.

    
20.07.2015 / 04:55