Today’s Regex is used to parse a string for Vimeo links and extract the Video_ID. Once we have the Video_ID we’re able to create a standard embed code from Vimeo links.

Supported Links:

The following Regex supports these Vimeo links and embed code snippets.

Normal URL: http://vimeo.com/9669721
Group URL:   http://vimeo.com/groups/tvc/videos/32626014
New Embed:   <iframe src="http://player.vimeo.com/video/9669721?title=0
             &byline=0&portrait=0&color=ffffff" width="400"
             height="225" frameborder="0" webkitAllowFullScreen
             mozallowfullscreen allowFullScreen > </iframe >

**** Doesn't handle Vimeo's old embed code ****


Again, I’ve broken it up the Regex and commented each line.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$regexstr = '~
 # Match Vimeo link and embed code
(?:<iframe [^>]*src=")? 	# If iframe match up to first quote of src
(?:				# Group vimeo url
	https?:\/\/		# Either http or https
	(?:[\w]+\.)*		# Optional subdomains
	vimeo\.com		# Match vimeo.com
	(?:[\/\w]*\/videos?)?	# Optional video sub directory this handles groups links also
	\/			# Slash before Id
	([0-9]+)		# $1: VIDEO_ID is numeric
	[^\s]*			# Not a space
)				# End group
"?				# Match end quote if part of src
(?:[^>]*></iframe>)?		# Match the end of the iframe
(?:<p>.*</p>)?		        # Match any title information stuff
~ix';

Usage Example:

This example function takes an input string and uses the above Regex to parse off the Vimeo Video_ID ($1) and add it to $iframestr to create a standard embed code.

1
2
3
4
5
6
function ParsePostVimeo($string){
	$regexstr = <<REGEX FROM ABOVE>>;
	$iframestr = ' <p><iframe src="http://player.vimeo.com/video/$1?title=0&amp;byline=0&amp;portrait=0" width="500" height="284" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe></iframe></p> ';
 
	return preg_replace($regexstr, $iframestr, $string);
}

For more Regex see Regex YouTube Parser

Tagged with:
 

One Response to Regex Vimeo Parser

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

Set your Twitter account name in your settings to use the TwitterBar Section.
film izle film izle film izle film izle film izle film izle film izle film izle dizi izle dizi izle film izle film izle film izle