RBA Cash Rate: 4.35% · 1AUD = 0.67 USD · Inflation: 4.1%  
Leading Digital Marketing Experts</strong | 1300 235 433 | Aggregation Enquires Welcome | Book Appointment
Example Interest Rates: Home Loan Variable: 5.69% (5.89%*) • Home Loan Fixed: 5.39% (6.59%*) • Fixed: 5.39% (6.59%*) • Variable: 5.69% (5.89%*) • Investment IO: 5.69% (6.48%*) • Investment PI: 5.39% (6.59%*)

Return an Inverse Color With PHP

The following PHP function will return an inverse HEX color with PHP. It's handy if you need to print readable text on a colored background. It's not always aesthetically pleasing so it's usually best to use a black, neutral, or white text overlay on a background based on the background color's numeric value.

1
<?php 
2
/*
3
 Return an Inverse Color With PHP
4
 http://www.beliefmedia.com/code/php-snippets/inverse-color-php
5
*/
6
 
7
function beliefmedia_inverse_color($color) {
8
 
9
  $color = str_replace('#', '', $color);
10
  if (strlen($color) != 6) $color = str_repeat(substr($color, 0, 1), 2) . str_repeat(substr($color, 1, 1), 2) . str_repeat(substr($color, 2, 1), 2);
11
 
12
  for ($x = 0; $x < 3; $x++) {
13
    $c = 255 - hexdec(substr($color, (2 * $x), 2));
14
    $c = ($c < 0) ? 0 : dechex($c);
15
    $hex .= (strlen($c) < 2) ? '0' . $c : $c;
16
  }
17
 
18
 return '#' . $hex;
19
}
20
 
21
/* Usage (returns #000000) */
22
echo beliefmedia_inverse_color($color = 'ffffff');
23
 
24
/* Usage (returns #00ffff) */
25
echo beliefmedia_inverse_color($color = 'ff0000');

Other color functions can be found on our blog by way of the color Tag: color tag.

■ ■ ■

 
Download our complimentary 650-page guide on marketing for mortgage brokers. We'll show you exactly how we generate billions in volume for our clients.
Finance Guide, Cropped Top and Bottom
  Timezone: 1 · [ CHANGE ]

Like this article?

Share on Facebook
Share on Twitter
Share on Linkdin
Share on Pinterest

Leave a comment