I created a UDT to convert HEX colors to RGB which works OK:
viewtopic.php?f=4&t=80592
The problem is that I can only use it once per page.
It breaks everything if I use it twice with different HEX colors.
Any ideas?
Simon66
UDT can only be used once per page
Re: UDT can only be used once per page
The UDT you created has a function declaration in it, so each time you call it you are re-declaring it which is a no no.
Try:
HTH
Try:
Code: Select all
$hex = $params['hex'];
$alpha = $params['alpha'];
$hex = str_replace('#', '', $hex);
$length = strlen($hex);
$rgb['r'] = hexdec($length == 6 ? substr($hex, 0, 2) : ($length == 3 ? str_repeat(substr($hex, 0, 1), 2) : 0));
$rgb['g'] = hexdec($length == 6 ? substr($hex, 2, 2) : ($length == 3 ? str_repeat(substr($hex, 1, 1), 2) : 0));
$rgb['b'] = hexdec($length == 6 ? substr($hex, 4, 2) : ($length == 3 ? str_repeat(substr($hex, 2, 1), 2) : 0));
if ( $alpha ) {
$rgb['a'] = $alpha;
}
echo implode(array_keys($rgb)) . '(' . implode(', ', $rgb) . ')';
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
Re: UDT can only be used once per page
Thanks Fernando
That works perfectly!
Cheers
Simon66
That works perfectly!
Cheers
Simon66