tvgemert
tvgemert

Reputation: 1486

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

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

I would like to use a regular 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?

Upvotes: 0

Views: 512

Answers (2)

Billy Moon
Billy Moon

Reputation: 58541

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

Upvotes: 3

LHMathies
LHMathies

Reputation: 2434

Try this:

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

Upvotes: 0

Related Questions