Reputation:
I'm trying to find all videos in a piece of html:
preg_match_all('[<iframe*]', $this->textile_text, $video_matches);
I'm using PHP.
Right now I am only matching iframe tags, I need to also look for embed and object tags. Those are the only ways I can think of videos being embedded in html.
How can I say "or" so this would work?
preg_match_all('[<iframe*] OR [<embed*] OR [<object*]', $this->textile_text, $video_matches);
Also if anyone can think of a better REGEX pattern to detect videos, that would be great because mine is quite elementary.
This produced this output:
preg_match_all("(iframe|embed|object)", $this->textile_text, $video_matches);
Array
(
[0] => Array
(
[0] => object
[1] => embed
[2] => embed
[3] => embed
[4] => embed
[5] => object
[6] => iframe
[7] => embed
[8] => iframe
[9] => iframe
[10] => embed
[11] => iframe
[12] => iframe
[13] => embed
[14] => iframe
[15] => iframe
[16] => embed
[17] => iframe
[18] => iframe
[19] => embed
[20] => iframe
[21] => iframe
[22] => embed
[23] => iframe
[24] => iframe
[25] => embed
[26] => iframe
)
)
Should have been:
Array
(
[0] => Array
(
[0] => <iframe
[1] => <iframe
[2] => <iframe
[3] => <iframe
[4] => <iframe
[5] => <iframe
[6] => <iframe
[7] => <embed
)
)
Upvotes: 1
Views: 1958
Reputation: 1691
I think this will get you what you need.
(iframe|embed|object)
This should match one of those three words according to the documentation. I however do not have access to the PHP specific versions of reg-ex to give this a go.
Upvotes: 1