Reputation: 241
I got some link like:
/3/topic/video1148288/
and I want to take the number after video. I can't replace the link with only numbers because there are more before the actual video's id.
I tried
$embed = preg_match("#\b/video([0-9][0-9][0-9][0-9][0-9][0-9][0-9])/#", $raw);
But it doesn't work.
Any help?
Upvotes: 2
Views: 79
Reputation: 295
preg_match('/(?<=video)\d+/i', $raw, $match);
echo $match[0];
Upvotes: 1
Reputation: 3478
$raw = "/3/topic/video1148288/";
preg_match("/video(\d+)/", $raw, $results);
print "$results[1]";
Upvotes: 1
Reputation: 28959
Give this a try:
$raw = "/3/topic/video1148288/";
preg_match("#/video(\d+)/#", $raw, $matches);
$embed = $matches[1];
Working example: http://3v4l.org/oLPMX
One thing to note from looking at your attempt, is that preg_match
returns a truthy/falsely value, not the actual matches. Those are found in the third param ($matches
in my example).
Upvotes: 1