Tuesday, 15 March 2011

regex - php preg_match parse histogram string -



regex - php preg_match parse histogram string -

i have imagemagick histogram color info in string, want parse string using php preg_match() function, sorry have not more knowledge regular expression.

<?php $str = "588: ( 99, 75, 52) #634b34 srgb(99,75,52)"; preg_match('/(?p<colors>\d+\:)/', $str, $matches); print_r($matches); ?>

expected output

array ( [colors] => 588, [red] => 99, [green] => 75, [blue] => 52 )

how desired output, or there way colors , density?

i think want this,

(?p<colors>\d+):\s*\(\s*(?p<red>\d+),\s*(?p<green>\d+),\s*(?p<blue>\d+)

demo

php regex imagemagick preg-match histogram

No comments:

Post a Comment