Skip to content

Instantly share code, notes, and snippets.

@mfields
Created December 10, 2011 19:34
Show Gist options
  • Select an option

  • Save mfields/1456066 to your computer and use it in GitHub Desktop.

Select an option

Save mfields/1456066 to your computer and use it in GitHub Desktop.
Is RGB(A)?
function is_rgb( $x ) {
if ( is_int( $x ) )
$x = strval( $x );
if ( ! is_string( $x ) )
return false;
$x = preg_replace( '/\s*/', '', $x );
$x = strtolower( $x );
$x = trim( $x );
if ( 0 !== preg_match( '/^[0-9a-fA-F]{3}$/', $x ) )
return true;
else if ( 0 !== preg_match( '/^[0-9a-fA-F]{6}$/', $x ) )
return true;
elseif ( 0 !== preg_match( '/^rgb\(\d{1,3},\d{1,3},\d{1,3}\)$/', $x ) )
return true;
else if ( 0 !== preg_match( '/^rgba\((\d{1,3},){3}(0(\.\d+)?|1)\)$/', $x ) )
return true;
return false;
}
@abou7mied
Copy link

Thank you very much..
finally i found it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment