Forum Moderators: coopster

Message Too Old, No Replies

Dividing a string into 2 letter pieces

         

Gero_Master

1:10 pm on Apr 7, 2006 (gmt 0)

10+ Year Member



Hello!

Google was no help when I tried to search for a function that would seperate a html color into 2 letter pieces. My code allready erases the # -sign in front of the color.

like: #a3f4f4
into: a3 f4 f4

which i could then use like
$c['0']
$c['1']
$c['2']

It needs to be divided for GD's color functions.

Thank you

omoutop

1:25 pm on Apr 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



$var = "FFCCDD";
$code1 = substr($var,0,-4); // FF
$code2 = substr($var,2,2); // CC
$code3 = substr($var,4,2); // DD

zCat

1:31 pm on Apr 7, 2006 (gmt 0)

10+ Year Member



Another possibility:

$string = 'AABBCC';
preg_match_all('(\w\w)', $string, $matches);

$matches becomes an array with $matches[0] containing "AA", etc.

Gero_Master

5:18 pm on Apr 7, 2006 (gmt 0)

10+ Year Member



Thanks for your replies ;)