php – preg_match_all to find text between strings

Question:

I would like to get the text between "play_url":" and "," using PHP's preg_match_all, but these quotes are complicating me and I don't even know where the tracking code would be, what I currently have is this:

$texto: '"play_url":"http:/video.server.com/","'
preg_match_all('/"play_url"(.*?) ","/i', $texto, $link);

Answer:

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

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

Lazy ( ? ) doesn't need it in this case either, as there is apparently no possibility of having another "," in the string.

I would be:

<?
$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 print the value:

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

IDEONE

Scroll to Top
AllEscort