开发者

Get an URL from text surrounded with curly braces using PHP Regular expression

开发者 https://www.devze.com 2023-03-17 20:12 出处:网络
I have the following text (inside some more text): {movie:http://www.film.com/films/film1} I would like to use a reg开发者_StackOverflow社区ular expression to get the url based on the fact that it\'s

I have the following text (inside some more text): {movie:http://www.film.com/films/film1}

I would like to use a reg开发者_StackOverflow社区ular expression to get the url based on the fact that it's wrapped inside curly braces and contains "movie:" after the first brace. How can I do this using PHP?


$t = "{movie:http://www.film.com/films/film1}";
preg_match(/{movie:([^}]+)}/,$t,$m);
$url = $m[1];


Try this:

if (preg_match('/\{movie:(.*?)}/', $text, $match))
    print "Found movie URL '".$match[1]."'\n";
0

精彩评论

暂无评论...
验证码 换一张
取 消