{"id":444,"date":"2014-09-05T14:38:05","date_gmt":"2014-09-05T20:38:05","guid":{"rendered":"http:\/\/weblizar.com\/?p=444"},"modified":"2014-09-05T14:38:05","modified_gmt":"2014-09-05T20:38:05","slug":"convert-hex-code-to-rgb-code-php","status":"publish","type":"post","link":"https:\/\/weblizar.com\/blog\/convert-hex-code-to-rgb-code-php\/","title":{"rendered":"How to convert Hex code to RGB code in php"},"content":{"rendered":"<p>Here Are some Steps to convert <strong>Hex colo<\/strong>r code to RGB color Code<\/p>\n<p><strong>Step-1 :<\/strong> \u00a0First write your php function for convert\u00a0<strong>Hex colo<\/strong>r<\/p>\n<pre>function hex2rgb($hex) {\n$hex = str_replace(\"#\", \"\", $hex);\n\nif(strlen($hex) == 3) {\n$r = hexdec(substr($hex,0,1).substr($hex,0,1));\n$g = hexdec(substr($hex,1,1).substr($hex,1,1));\n$b = hexdec(substr($hex,2,1).substr($hex,2,1));\n} else {\n$r = hexdec(substr($hex,0,2));\n$g = hexdec(substr($hex,2,2));\n$b = hexdec(substr($hex,4,2));\n}\n$rgb = array($r, $g, $b);\n\nreturn $rgb; \/\/ returns an array with the rgb values\n}\n<\/pre>\n<p><strong>Step-2\u00a0<\/strong>\u00a0: \u00a0Call this function everywhere where you want to get converted hex color code here an example that how to call this fucntion<\/p>\n<pre>$Hex_color = \"#31A#DD\";\n$RGB_color = hex2rgb($Hex_color);\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Step-3 \u00a0: \u00a0<\/strong>Echo this variable at where there you want to show rgb color but first implode this variable using comma\u00a0here an example<\/p>\n<pre>$Final_Rgb_color = implode(\", \", $RGB_color);<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Step-4<\/strong> : \u00a0Use this code in style , Here is an example<\/p>\n<pre>&lt;style&gt;\n\n.container {\n\nbackground : rgba(&lt;?php echo $Final_Rgb_color; \u00a0?&gt;,1);\n\n}\n\n&lt;\/style&gt;\n<\/pre>\n<p>&nbsp;<\/p>\n<p>Thanks<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here Are some Steps to convert Hex color code to RGB color Code Step-1 : \u00a0First write your php function for convert\u00a0Hex color function hex2rgb($hex) { $hex = str_replace(&#8220;#&#8221;, &#8220;&#8221;, $hex); if(strlen($hex) == 3) { $r = hexdec(substr($hex,0,1).substr($hex,0,1)); $g = hexdec(substr($hex,1,1).substr($hex,1,1)); $b = hexdec(substr($hex,2,1).substr($hex,2,1)); } else { $r = hexdec(substr($hex,0,2)); $g = hexdec(substr($hex,2,2)); $b =<\/p>\n","protected":false},"author":1,"featured_media":450,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[77],"tags":[],"class_list":["post-444","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to convert Hex code to RGB code in php - Weblizar Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/weblizar.com\/blog\/convert-hex-code-to-rgb-code-php\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to convert Hex code to RGB code in php - Weblizar Blog\" \/>\n<meta property=\"og:description\" content=\"Here Are some Steps to convert Hex color code to RGB color Code Step-1 : \u00a0First write your php function for convert\u00a0Hex color function hex2rgb($hex) { $hex = str_replace(&quot;#&quot;, &quot;&quot;, $hex); if(strlen($hex) == 3) { $r = hexdec(substr($hex,0,1).substr($hex,0,1)); $g = hexdec(substr($hex,1,1).substr($hex,1,1)); $b = hexdec(substr($hex,2,1).substr($hex,2,1)); } else { $r = hexdec(substr($hex,0,2)); $g = hexdec(substr($hex,2,2)); $b =\" \/>\n<meta property=\"og:url\" content=\"https:\/\/weblizar.com\/blog\/convert-hex-code-to-rgb-code-php\/\" \/>\n<meta property=\"og:site_name\" content=\"Weblizar Blog\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/www.facebook.com\/weblizarwp\" \/>\n<meta property=\"article:published_time\" content=\"2014-09-05T20:38:05+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/i0.wp.com\/weblizar.com\/blog\/wp-content\/uploads\/2014\/09\/hex-to-rgb.png?fit=1211%2C696&ssl=1\" \/>\n\t<meta property=\"og:image:width\" content=\"1211\" \/>\n\t<meta property=\"og:image:height\" content=\"696\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"weblizar\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@weblizar\" \/>\n<meta name=\"twitter:site\" content=\"@weblizar\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"weblizar\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to convert Hex code to RGB code in php - Weblizar Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/weblizar.com\/blog\/convert-hex-code-to-rgb-code-php\/","og_locale":"en_US","og_type":"article","og_title":"How to convert Hex code to RGB code in php - Weblizar Blog","og_description":"Here Are some Steps to convert Hex color code to RGB color Code Step-1 : \u00a0First write your php function for convert\u00a0Hex color function hex2rgb($hex) { $hex = str_replace(\"#\", \"\", $hex); if(strlen($hex) == 3) { $r = hexdec(substr($hex,0,1).substr($hex,0,1)); $g = hexdec(substr($hex,1,1).substr($hex,1,1)); $b = hexdec(substr($hex,2,1).substr($hex,2,1)); } else { $r = hexdec(substr($hex,0,2)); $g = hexdec(substr($hex,2,2)); $b =","og_url":"https:\/\/weblizar.com\/blog\/convert-hex-code-to-rgb-code-php\/","og_site_name":"Weblizar Blog","article_publisher":"http:\/\/www.facebook.com\/weblizarwp","article_published_time":"2014-09-05T20:38:05+00:00","og_image":[{"width":1211,"height":696,"url":"https:\/\/i0.wp.com\/weblizar.com\/blog\/wp-content\/uploads\/2014\/09\/hex-to-rgb.png?fit=1211%2C696&ssl=1","type":"image\/png"}],"author":"weblizar","twitter_card":"summary_large_image","twitter_creator":"@weblizar","twitter_site":"@weblizar","twitter_misc":{"Written by":"weblizar","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/weblizar.com\/blog\/convert-hex-code-to-rgb-code-php\/#article","isPartOf":{"@id":"https:\/\/weblizar.com\/blog\/convert-hex-code-to-rgb-code-php\/"},"author":{"name":"weblizar","@id":"https:\/\/weblizar.com\/blog\/#\/schema\/person\/8bd0de51e6e797ea0402f3ffa858a413"},"headline":"How to convert Hex code to RGB code in php","datePublished":"2014-09-05T20:38:05+00:00","mainEntityOfPage":{"@id":"https:\/\/weblizar.com\/blog\/convert-hex-code-to-rgb-code-php\/"},"wordCount":93,"commentCount":0,"image":{"@id":"https:\/\/weblizar.com\/blog\/convert-hex-code-to-rgb-code-php\/#primaryimage"},"thumbnailUrl":"https:\/\/weblizar.com\/blog\/wp-content\/uploads\/2014\/09\/hex-to-rgb.png","articleSection":["Php"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/weblizar.com\/blog\/convert-hex-code-to-rgb-code-php\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/weblizar.com\/blog\/convert-hex-code-to-rgb-code-php\/","url":"https:\/\/weblizar.com\/blog\/convert-hex-code-to-rgb-code-php\/","name":"How to convert Hex code to RGB code in php - Weblizar Blog","isPartOf":{"@id":"https:\/\/weblizar.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/weblizar.com\/blog\/convert-hex-code-to-rgb-code-php\/#primaryimage"},"image":{"@id":"https:\/\/weblizar.com\/blog\/convert-hex-code-to-rgb-code-php\/#primaryimage"},"thumbnailUrl":"https:\/\/weblizar.com\/blog\/wp-content\/uploads\/2014\/09\/hex-to-rgb.png","datePublished":"2014-09-05T20:38:05+00:00","author":{"@id":"https:\/\/weblizar.com\/blog\/#\/schema\/person\/8bd0de51e6e797ea0402f3ffa858a413"},"breadcrumb":{"@id":"https:\/\/weblizar.com\/blog\/convert-hex-code-to-rgb-code-php\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/weblizar.com\/blog\/convert-hex-code-to-rgb-code-php\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/weblizar.com\/blog\/convert-hex-code-to-rgb-code-php\/#primaryimage","url":"https:\/\/weblizar.com\/blog\/wp-content\/uploads\/2014\/09\/hex-to-rgb.png","contentUrl":"https:\/\/weblizar.com\/blog\/wp-content\/uploads\/2014\/09\/hex-to-rgb.png","width":1211,"height":696},{"@type":"BreadcrumbList","@id":"https:\/\/weblizar.com\/blog\/convert-hex-code-to-rgb-code-php\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/weblizar.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to convert Hex code to RGB code in php"}]},{"@type":"WebSite","@id":"https:\/\/weblizar.com\/blog\/#website","url":"https:\/\/weblizar.com\/blog\/","name":"Weblizar Blog","description":"Update yourself with all the latest tech news revolving around wordpress all at one place","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/weblizar.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/weblizar.com\/blog\/#\/schema\/person\/8bd0de51e6e797ea0402f3ffa858a413","name":"weblizar","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/83d3ba133e1fd5422595fc5deff6340a4c654d5372f5805eca8c25450ecdef1b?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/83d3ba133e1fd5422595fc5deff6340a4c654d5372f5805eca8c25450ecdef1b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/83d3ba133e1fd5422595fc5deff6340a4c654d5372f5805eca8c25450ecdef1b?s=96&d=mm&r=g","caption":"weblizar"}}]}},"_links":{"self":[{"href":"https:\/\/weblizar.com\/blog\/wp-json\/wp\/v2\/posts\/444","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/weblizar.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/weblizar.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/weblizar.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/weblizar.com\/blog\/wp-json\/wp\/v2\/comments?post=444"}],"version-history":[{"count":0,"href":"https:\/\/weblizar.com\/blog\/wp-json\/wp\/v2\/posts\/444\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/weblizar.com\/blog\/wp-json\/wp\/v2\/media\/450"}],"wp:attachment":[{"href":"https:\/\/weblizar.com\/blog\/wp-json\/wp\/v2\/media?parent=444"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/weblizar.com\/blog\/wp-json\/wp\/v2\/categories?post=444"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/weblizar.com\/blog\/wp-json\/wp\/v2\/tags?post=444"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}