lowe_22
lowe_22

Reputation: 395

Check regular expressions php

I have a string with a number of 'shortcodes' in thus (just using an example):

$str = "[video src="http://www.aaa..." options="autoplay controls loop mute"]\n
        [video src=" http://www.bbb..." options="autoplay controls loop mute"]";

I'm trying to match each one independantly using preg_match() thus:

pregmatch( '/\[video.*\]/', $str, $matches );

Now I expect count($matches); to return '2'. But I only get 1 each time. Is my regular expression wrong? I need to assaign each [video ...... ] to a new array item so I can deal with them individually.

Thanks

Upvotes: 1

Views: 42

Answers (1)

codaddict
codaddict

Reputation: 454960

You need to use preg_match_all:

preg_match_all( '/\[video.*\]/', $str, $matches );

See it

Upvotes: 2

Related Questions