Reputation: 3463
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?
Upvotes: 2
Views: 48
Reputation: 15097
Your regexp is messy.
$regex = '/{ *(slider|slider-alt|video) *:\d+ *}/';
$matches = array();
preg_match_all( $regex, $row->content, $matches );
Upvotes: 2