iwant to get the video url from a object/embed html source. i read i can use regular expression to get it but me and regular expression are no friends
so heres what i have:
<?php
function src($text) {
$text = str_replace('"', '', $text);
$text = str_replace('src=', '', $text);
$temporary = explode('<embed', $text);
$temporary = $temporary[1];
$temporary = explode(' ', trim($temporary));
return $temporary[0];
}
$html = '
<object width="180" height="220">
<param name="movie" value="http://www.domain.com/video/video1.swf"></param>
<embed src="http://www.domain.com/video/video1.swf" type="application/x-shockwave-flash" width="180" height="220"></embed>
</object>
';
echo src($html);
this works but is it better in regular expression?
i am using lamp
A regular expression is better for this case because the
srcmight never be at the first attribute, therefore this won’t work.Here’s what I recommend:
will output:
http://www.domain.com/video/video1.swf[^>]matches a single character that is not contained within the brackets. [^>] matches any character other than>["\']matchessrc="orsrc='(.*?)Dot (.) means match any character. Star (*) means zero or more times. And question mark (?) means be greedy and keep going as long as the pattern still matches. Put it all together, it means try and match any character, zero or more times, and get as many as you can/iis case insensitiveHere’s more info:
http://en.wikipedia.org/wiki/Regular_expression
http://www.regular-expressions.info/reference.html