I have a block of text where I need yo find bits of text like: {slider:1} {video-alt:10}
I have this bit of code
$regex = '/{[ ]*(slider)|(slider-alt)|(video)[ ]*:[0-9]+[ ]*}/';
$matches = array();
preg_match_all( $regex, $row->content, $matches );
But the array returned is all messed up...
Array output:
Array ( [0] => {slider [1] => {slider [2] => video:2} )
Array ( [0] => slider [1] => slider [2] => )
Array ( [0] => [1] => [2] => )
Array ( [0] => [1] => [2] => video )
For the input:
{slider:6}
{slider-alt:2}
{video:2}
Any help?
Your regexp is messy.
$regex = '/{ *(slider|slider-alt|video) *:\d+ *}/';
$matches = array();
preg_match_all( $regex, $row->content, $matches );
var_dump($matches[0]);
gives array(3) { [0]=> string(10) "{slider:6}" [1]=> string(14) "{slider-alt:2}" [2]=> string(9) "{video:2}" }
meze 2012-04-04 07:23