Reply to Re: newbie question - variable data types?

Your name:

Reply:


Posted by Norman Peelman on 09/04/07 02:46

Nerd Monster wrote:
> I'm sure the solution to this is very simple and I'm just overlooking
> something. I'm using the following code to color an image:
>
> $thishex= 0xFF0000;
> $red = imagecolorallocate($im, 0, 0, $thishex);
>
> That works perfect. The problem is, the hex color is coming in the URL
> string, without the preceding "0x". To remedy this, I tried:
>
> $hex1 = "0x";
> $hex2 = "FF0000";
> $thishex = $hex1 . $hex2;
> $red = imagecolorallocate($im, 0, 0, $thishex);
>
> This does not work, despite the fact that it echos 0xFF0000. As a flash
> developer, I have run up against this problem before when I don't use strict
> data types. As a php newbie, I am not sure that there is a similar
> phenomenon in PHP.
>
> Anybody got the answer to this one? I'm sure it's very simple.
>
>
>
>
>

Two problems:

1) 0xFF0000 = 16711680 (not 255 like you want)
2) Your second example is using a string (which equates to 0), not a
hexadecimal value.

As long as $hex is a string (as it should be coming in as GET/POST/REQUEST:

This will work with or without adding '0x',

$red = imagecolorallocate($im, 0, 0, base_convert($hex, 16, 10)/512/128))

This will only work if you add '0x' to it:

$red = imagecolorallocate($im, 0, 0, ($hex/512/128))


Norm

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация