preg_match_all to find text between strings

3

I would like to get the text between "play_url":" and "," using PHP's preg_match_all, but those quotes are complicating me and I do not even know the direction it would be for the tracking code, what I currently have is this: p>

$texto: '"play_url":"http:/video.server.com/","'
preg_match_all('/"play_url"(.*?) ","/i', $texto, $link);
    
asked by anonymous 20.11.2018 / 00:42

1 answer

1

The code is almost certain, except for the space after the group and the :" is also missing after the "play_url" :

                          :"
                           ↓   ↓
preg_match_all('/"play_url"(.*) ","/i', $texto, $link);

The lazy ( ? ) also does not need in this case, since there is apparently no possibility of having another "," in the string.

I would stay:

<?
$texto = '"play_url":"http:/video.server.com/","';
preg_match_all('/"play_url":"(.*)","/i', $texto, $link);
var_dump($link[1]); // mostra array(1) { [0]=> string(23) "http:/video.server.com/" }
?>

To set the value:

echo $link[1][0]; // http:/video.server.com/

IDEONE

    
20.11.2018 / 01:11