James Harding
James Harding

Reputation: 69

PHP Colour Not Being Acknowledged

I am doing some testing with FPDF and running into an issue. When setting a container to pull it's colour from a pre-defined variable it is not honoring the value and I can't see why not. Example below

This works perfectly:

$pdf->SetFillColor(131,54,112);

However when trying to pull the value from a variable, it does not honor the value

$colour = '131,54,112';
$pdf->SetFillColor($colour);

Anyone with any ideas?

Upvotes: 0

Views: 78

Answers (2)

Markus Zeller
Markus Zeller

Reputation: 9090

You need to pass this values as single parameters. Split them first like this:

list($r, $g, $b) = explode(',', '131,54,112');
$pdf->SetFillColor($r, $g, $b);

Upvotes: 3

Mark
Mark

Reputation: 1872

'131,54,112' is a string, so it is one argument.

131,54,112 is three individual arguments.

I'm not actually sure if it is even possible to pass through one variable as three separate arguments, that wouldn't be logical, you are best off storing the values separately if you want to make them dynamic, like so:

$red = 131;
$green = 54;
$blue = 112;

$pdf->SetFillColor($red, $green, $blue);

Upvotes: 3

Related Questions