The g
modifier is not used in PHP. Use preg_match_all()
instead.
Further more, the arguments for preg_match
are in the wrong order. The arguments need to be in this order:
preg_match($pattern, $videoTest, $matches);
Read the Regular Expressions documentation.
A more robust way of retrieving stuff from a string using regular expressions it to be as specific as possible. This prevents malformed stuff from getting through. For example:
function getJQPlayer($string) {
$pattern = '/\[jwplayer(?:\s+[\w\d]+=(["\'])[\w\d]+\\1)*\]/';
preg_match_all($pattern, $string, $matches, PREG_SET_ORDER);
foreach ($matches as & $match) {
$match = array_shift($match);
}
return $matches ?: FALSE;
}
$videoTest = "[jwplayer config=\"top_10_videos\" mediaid=\"107\"]";
$videoTest .= ",[jwplayer config=\"bottom_10_videos\" mediaid=\"108\"]";
echo '<pre>', print_r(getJQPlayer($videoTest), true);