Created
December 10, 2011 19:34
-
-
Save mfields/1456066 to your computer and use it in GitHub Desktop.
Is RGB(A)?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you very much..
finally i found it :)