Из RGB в код для HTML

Ответить
Аватара пользователя
Flesh
Сообщения: 16
Зарегистрирован: 23.09.2010
Здравствуйте.
У меня есть код который выводит

Код: Выделить всё

              $s = 0;
              for ( $b=0; $b<257; $b=$b+51 ) {
                echo "<tr>\n                      ";
                for ( $r=0; $r<257; $r=$r+51 ) {
                    for ( $g=0; $g<257; $g=$g+51 ) {
                        $color = str_pad(dechex($r), 2, '0', STR_PAD_LEFT).str_pad(dechex($g), 2, '0', STR_PAD_LEFT).str_pad(dechex($b), 2, '0', STR_PAD_LEFT);
                        echo "<td style='background-color:#$color' >&nbsp;</td>\n                      ";
                    }
                }
                $color = str_pad(dechex($s), 2, '0', STR_PAD_LEFT).str_pad(dechex($s), 2, '0', STR_PAD_LEFT).str_pad(dechex($s), 2, '0', STR_PAD_LEFT);
                echo "<td style='background-color:#$color' >&nbsp;</td>\n                      </tr>\n                      ";
                $s=$s+23;
              }
Он выводит RGB цвета типо rgb(211,179,53) а мне нужно что бы вывадило так: #d2b334
Как сделать ?
Мастерство программирования не в том, что бы писать программы без ошибок,
а в том, что бы писать программы работающие при любом количестве ошибок.

Аватара пользователя
Distructor
Администратор
Сообщения: 1607
Зарегистрирован: 28.12.2009
код-то выводит в нужном виде.. я ж сам его писал..

значит Crank174RuS начал раздавать код написанный мной на заказ для него..

Аватара пользователя
Flesh
Сообщения: 16
Зарегистрирован: 23.09.2010
На FireFoxe не работает
Crank174Rus я очень давно знаю мы с ним вместе пишем мониторинг
Он не дурак что бы деньгами на ветер брасатся
Мастерство программирования не в том, что бы писать программы без ошибок,
а в том, что бы писать программы работающие при любом количестве ошибок.

Аватара пользователя
Distructor
Администратор
Сообщения: 1607
Зарегистрирован: 28.12.2009
Flesh писал(а):На FireFoxe не работает
что именно не работает? скрин приложи и заодно сформированный html-код, в котором ты увидел rgb(x,x,x).

Аватара пользователя
Flesh
Сообщения: 16
Зарегистрирован: 23.09.2010
Вот сформированный код

Код: Выделить всё

                <table class="color_tbl" id="m_colors" border="0" cellspacing="1">
                      <tbody><tr>
                      <td style="background-color: rgb(0, 0, 0);">&nbsp;</td>
                      <td style="background-color: rgb(0, 51, 0);">&nbsp;</td>
                      <td style="background-color: rgb(0, 102, 0);">&nbsp;</td>
                      <td style="background-color: rgb(0, 153, 0);">&nbsp;</td>

                      <td style="background-color: rgb(0, 204, 0);">&nbsp;</td>
                      <td style="background-color: rgb(0, 255, 0);">&nbsp;</td>
                      <td style="background-color: rgb(51, 0, 0);">&nbsp;</td>
                      <td style="background-color: rgb(51, 51, 0);">&nbsp;</td>
                      <td style="background-color: rgb(51, 102, 0);">&nbsp;</td>
                      <td style="background-color: rgb(51, 153, 0);">&nbsp;</td>
                      <td style="background-color: rgb(51, 204, 0);">&nbsp;</td>
                      <td style="background-color: rgb(51, 255, 0);">&nbsp;</td>
                      <td style="background-color: rgb(102, 0, 0);">&nbsp;</td>

                      <td style="background-color: rgb(102, 51, 0);">&nbsp;</td>
                      <td style="background-color: rgb(102, 102, 0);">&nbsp;</td>
                      <td style="background-color: rgb(102, 153, 0);">&nbsp;</td>
                      <td style="background-color: rgb(102, 204, 0);">&nbsp;</td>
                      <td style="background-color: rgb(102, 255, 0);">&nbsp;</td>
                      <td style="background-color: rgb(153, 0, 0);">&nbsp;</td>
                      <td style="background-color: rgb(153, 51, 0);">&nbsp;</td>
                      <td style="background-color: rgb(153, 102, 0);">&nbsp;</td>
                      <td style="background-color: rgb(153, 153, 0);">&nbsp;</td>

                      <td style="background-color: rgb(153, 204, 0);">&nbsp;</td>
                      <td style="background-color: rgb(153, 255, 0);">&nbsp;</td>
                      <td style="background-color: rgb(204, 0, 0);">&nbsp;</td>
                      <td style="background-color: rgb(204, 51, 0);">&nbsp;</td>
                      <td style="background-color: rgb(204, 102, 0);">&nbsp;</td>
                      <td style="background-color: rgb(204, 153, 0);">&nbsp;</td>
                      <td style="background-color: rgb(204, 204, 0);">&nbsp;</td>
                      <td style="background-color: rgb(204, 255, 0);">&nbsp;</td>
                      <td style="background-color: rgb(255, 0, 0);">&nbsp;</td>

                      <td style="background-color: rgb(255, 51, 0);">&nbsp;</td>
                      <td style="background-color: rgb(255, 102, 0);">&nbsp;</td>
                      <td style="background-color: rgb(255, 153, 0);">&nbsp;</td>
                      <td style="background-color: rgb(255, 204, 0);">&nbsp;</td>
                      <td style="background-color: rgb(255, 255, 0);">&nbsp;</td>
                      <td style="background-color: rgb(0, 0, 0);">&nbsp;</td>
                      </tr>
                      <tr>
                      <td style="background-color: rgb(0, 0, 51);">&nbsp;</td>

                      <td style="background-color: rgb(0, 51, 51);">&nbsp;</td>
                      <td style="background-color: rgb(0, 102, 51);">&nbsp;</td>
                      <td style="background-color: rgb(0, 153, 51);">&nbsp;</td>
                      <td style="background-color: rgb(0, 204, 51);">&nbsp;</td>
                      <td style="background-color: rgb(0, 255, 51);">&nbsp;</td>
                      <td style="background-color: rgb(51, 0, 51);">&nbsp;</td>
                      <td style="background-color: rgb(51, 51, 51);">&nbsp;</td>
                      <td style="background-color: rgb(51, 102, 51);">&nbsp;</td>
                      <td style="background-color: rgb(51, 153, 51);">&nbsp;</td>

                      <td style="background-color: rgb(51, 204, 51);">&nbsp;</td>
                      <td style="background-color: rgb(51, 255, 51);">&nbsp;</td>
                      <td style="background-color: rgb(102, 0, 51);">&nbsp;</td>
                      <td style="background-color: rgb(102, 51, 51);">&nbsp;</td>
                      <td style="background-color: rgb(102, 102, 51);">&nbsp;</td>
                      <td style="background-color: rgb(102, 153, 51);">&nbsp;</td>
                      <td style="background-color: rgb(102, 204, 51);">&nbsp;</td>
                      <td style="background-color: rgb(102, 255, 51);">&nbsp;</td>
                      <td style="background-color: rgb(153, 0, 51);">&nbsp;</td>

                      <td style="background-color: rgb(153, 51, 51);">&nbsp;</td>
                      <td style="background-color: rgb(153, 102, 51);">&nbsp;</td>
                      <td style="background-color: rgb(153, 153, 51);">&nbsp;</td>
                      <td style="background-color: rgb(153, 204, 51);">&nbsp;</td>
                      <td style="background-color: rgb(153, 255, 51);">&nbsp;</td>
                      <td style="background-color: rgb(204, 0, 51);">&nbsp;</td>
                      <td style="background-color: rgb(204, 51, 51);">&nbsp;</td>
                      <td style="background-color: rgb(204, 102, 51);">&nbsp;</td>
                      <td style="background-color: rgb(204, 153, 51);">&nbsp;</td>

                      <td style="background-color: rgb(204, 204, 51);">&nbsp;</td>
                      <td style="background-color: rgb(204, 255, 51);">&nbsp;</td>
                      <td style="background-color: rgb(255, 0, 51);">&nbsp;</td>
                      <td style="background-color: rgb(255, 51, 51);">&nbsp;</td>
                      <td style="background-color: rgb(255, 102, 51);">&nbsp;</td>
                      <td style="background-color: rgb(255, 153, 51);">&nbsp;</td>
                      <td style="background-color: rgb(255, 204, 51);">&nbsp;</td>
                      <td style="background-color: rgb(255, 255, 51);">&nbsp;</td>
                      <td style="background-color: rgb(23, 23, 23);">&nbsp;</td>

                      </tr>
                      <tr>
                      <td style="background-color: rgb(0, 0, 102);">&nbsp;</td>
                      <td style="background-color: rgb(0, 51, 102);">&nbsp;</td>
                      <td style="background-color: rgb(0, 102, 102);">&nbsp;</td>
                      <td style="background-color: rgb(0, 153, 102);">&nbsp;</td>
                      <td style="background-color: rgb(0, 204, 102);">&nbsp;</td>
                      <td style="background-color: rgb(0, 255, 102);">&nbsp;</td>
                      <td style="background-color: rgb(51, 0, 102);">&nbsp;</td>

                      <td style="background-color: rgb(51, 51, 102);">&nbsp;</td>
                      <td style="background-color: rgb(51, 102, 102);">&nbsp;</td>
                      <td style="background-color: rgb(51, 153, 102);">&nbsp;</td>
                      <td style="background-color: rgb(51, 204, 102);">&nbsp;</td>
                      <td style="background-color: rgb(51, 255, 102);">&nbsp;</td>
                      <td style="background-color: rgb(102, 0, 102);">&nbsp;</td>
                      <td style="background-color: rgb(102, 51, 102);">&nbsp;</td>
                      <td style="background-color: rgb(102, 102, 102);">&nbsp;</td>
                      <td style="background-color: rgb(102, 153, 102);">&nbsp;</td>

                      <td style="background-color: rgb(102, 204, 102);">&nbsp;</td>
                      <td style="background-color: rgb(102, 255, 102);">&nbsp;</td>
                      <td style="background-color: rgb(153, 0, 102);">&nbsp;</td>
                      <td style="background-color: rgb(153, 51, 102);">&nbsp;</td>
                      <td style="background-color: rgb(153, 102, 102);">&nbsp;</td>
                      <td style="background-color: rgb(153, 153, 102);">&nbsp;</td>
                      <td style="background-color: rgb(153, 204, 102);">&nbsp;</td>
                      <td style="background-color: rgb(153, 255, 102);">&nbsp;</td>
                      <td style="background-color: rgb(204, 0, 102);">&nbsp;</td>

                      <td style="background-color: rgb(204, 51, 102);">&nbsp;</td>
                      <td style="background-color: rgb(204, 102, 102);">&nbsp;</td>
                      <td style="background-color: rgb(204, 153, 102);">&nbsp;</td>
                      <td style="background-color: rgb(204, 204, 102);">&nbsp;</td>
                      <td style="background-color: rgb(204, 255, 102);">&nbsp;</td>
                      <td style="background-color: rgb(255, 0, 102);">&nbsp;</td>
                      <td style="background-color: rgb(255, 51, 102);">&nbsp;</td>
                      <td style="background-color: rgb(255, 102, 102);">&nbsp;</td>
                      <td style="background-color: rgb(255, 153, 102);">&nbsp;</td>

                      <td style="background-color: rgb(255, 204, 102);">&nbsp;</td>
                      <td style="background-color: rgb(255, 255, 102);">&nbsp;</td>
                      <td style="background-color: rgb(46, 46, 46);">&nbsp;</td>
                      </tr>
                      <tr>
                      <td style="background-color: rgb(0, 0, 153);">&nbsp;</td>
                      <td style="background-color: rgb(0, 51, 153);">&nbsp;</td>
                      <td style="background-color: rgb(0, 102, 153);">&nbsp;</td>
                      <td style="background-color: rgb(0, 153, 153);">&nbsp;</td>

                      <td style="background-color: rgb(0, 204, 153);">&nbsp;</td>
                      <td style="background-color: rgb(0, 255, 153);">&nbsp;</td>
                      <td style="background-color: rgb(51, 0, 153);">&nbsp;</td>
                      <td style="background-color: rgb(51, 51, 153);">&nbsp;</td>
                      <td style="background-color: rgb(51, 102, 153);">&nbsp;</td>
                      <td style="background-color: rgb(51, 153, 153);">&nbsp;</td>
                      <td style="background-color: rgb(51, 204, 153);">&nbsp;</td>
                      <td style="background-color: rgb(51, 255, 153);">&nbsp;</td>
                      <td style="background-color: rgb(102, 0, 153);">&nbsp;</td>

                      <td style="background-color: rgb(102, 51, 153);">&nbsp;</td>
                      <td style="background-color: rgb(102, 102, 153);">&nbsp;</td>
                      <td style="background-color: rgb(102, 153, 153);">&nbsp;</td>
                      <td style="background-color: rgb(102, 204, 153);">&nbsp;</td>
                      <td style="background-color: rgb(102, 255, 153);">&nbsp;</td>
                      <td style="background-color: rgb(153, 0, 153);">&nbsp;</td>
                      <td style="background-color: rgb(153, 51, 153);">&nbsp;</td>
                      <td style="background-color: rgb(153, 102, 153);">&nbsp;</td>
                      <td style="background-color: rgb(153, 153, 153);">&nbsp;</td>

                      <td style="background-color: rgb(153, 204, 153);">&nbsp;</td>
                      <td style="background-color: rgb(153, 255, 153);">&nbsp;</td>
                      <td style="background-color: rgb(204, 0, 153);">&nbsp;</td>
                      <td style="background-color: rgb(204, 51, 153);">&nbsp;</td>
                      <td style="background-color: rgb(204, 102, 153);">&nbsp;</td>
                      <td style="background-color: rgb(204, 153, 153);">&nbsp;</td>
                      <td style="background-color: rgb(204, 204, 153);">&nbsp;</td>
                      <td style="background-color: rgb(204, 255, 153);">&nbsp;</td>
                      <td style="background-color: rgb(255, 0, 153);">&nbsp;</td>

                      <td style="background-color: rgb(255, 51, 153);">&nbsp;</td>
                      <td style="background-color: rgb(255, 102, 153);">&nbsp;</td>
                      <td style="background-color: rgb(255, 153, 153);">&nbsp;</td>
                      <td style="background-color: rgb(255, 204, 153);">&nbsp;</td>
                      <td style="background-color: rgb(255, 255, 153);">&nbsp;</td>
                      <td style="background-color: rgb(69, 69, 69);">&nbsp;</td>
                      </tr>
                      <tr>
                      <td style="background-color: rgb(0, 0, 204);">&nbsp;</td>

                      <td style="background-color: rgb(0, 51, 204);">&nbsp;</td>
                      <td style="background-color: rgb(0, 102, 204);">&nbsp;</td>
                      <td style="background-color: rgb(0, 153, 204);">&nbsp;</td>
                      <td style="background-color: rgb(0, 204, 204);">&nbsp;</td>
                      <td style="background-color: rgb(0, 255, 204);">&nbsp;</td>
                      <td style="background-color: rgb(51, 0, 204);">&nbsp;</td>
                      <td style="background-color: rgb(51, 51, 204);">&nbsp;</td>
                      <td style="background-color: rgb(51, 102, 204);">&nbsp;</td>
                      <td style="background-color: rgb(51, 153, 204);">&nbsp;</td>

                      <td style="background-color: rgb(51, 204, 204);">&nbsp;</td>
                      <td style="background-color: rgb(51, 255, 204);">&nbsp;</td>
                      <td style="background-color: rgb(102, 0, 204);">&nbsp;</td>
                      <td style="background-color: rgb(102, 51, 204);">&nbsp;</td>
                      <td style="background-color: rgb(102, 102, 204);">&nbsp;</td>
                      <td style="background-color: rgb(102, 153, 204);">&nbsp;</td>
                      <td style="background-color: rgb(102, 204, 204);">&nbsp;</td>
                      <td style="background-color: rgb(102, 255, 204);">&nbsp;</td>
                      <td style="background-color: rgb(153, 0, 204);">&nbsp;</td>

                      <td style="background-color: rgb(153, 51, 204);">&nbsp;</td>
                      <td style="background-color: rgb(153, 102, 204);">&nbsp;</td>
                      <td style="background-color: rgb(153, 153, 204);">&nbsp;</td>
                      <td style="background-color: rgb(153, 204, 204);">&nbsp;</td>
                      <td style="background-color: rgb(153, 255, 204);">&nbsp;</td>
                      <td style="background-color: rgb(204, 0, 204);">&nbsp;</td>
                      <td style="background-color: rgb(204, 51, 204);">&nbsp;</td>
                      <td style="background-color: rgb(204, 102, 204);">&nbsp;</td>
                      <td style="background-color: rgb(204, 153, 204);">&nbsp;</td>

                      <td style="background-color: rgb(204, 204, 204);">&nbsp;</td>
                      <td style="background-color: rgb(204, 255, 204);">&nbsp;</td>
                      <td style="background-color: rgb(255, 0, 204);">&nbsp;</td>
                      <td style="background-color: rgb(255, 51, 204);">&nbsp;</td>
                      <td style="background-color: rgb(255, 102, 204);">&nbsp;</td>
                      <td style="background-color: rgb(255, 153, 204);">&nbsp;</td>
                      <td style="background-color: rgb(255, 204, 204);">&nbsp;</td>
                      <td style="background-color: rgb(255, 255, 204);">&nbsp;</td>
                      <td style="background-color: rgb(92, 92, 92);">&nbsp;</td>

                      </tr>
                      <tr>
                      <td style="background-color: rgb(0, 0, 255);">&nbsp;</td>
                      <td style="background-color: rgb(0, 51, 255);">&nbsp;</td>
                      <td style="background-color: rgb(0, 102, 255);">&nbsp;</td>
                      <td style="background-color: rgb(0, 153, 255);">&nbsp;</td>
                      <td style="background-color: rgb(0, 204, 255);">&nbsp;</td>
                      <td style="background-color: rgb(0, 255, 255);">&nbsp;</td>
                      <td style="background-color: rgb(51, 0, 255);">&nbsp;</td>

                      <td style="background-color: rgb(51, 51, 255);">&nbsp;</td>
                      <td style="background-color: rgb(51, 102, 255);">&nbsp;</td>
                      <td style="background-color: rgb(51, 153, 255);">&nbsp;</td>
                      <td style="background-color: rgb(51, 204, 255);">&nbsp;</td>
                      <td style="background-color: rgb(51, 255, 255);">&nbsp;</td>
                      <td style="background-color: rgb(102, 0, 255);">&nbsp;</td>
                      <td style="background-color: rgb(102, 51, 255);">&nbsp;</td>
                      <td style="background-color: rgb(102, 102, 255);">&nbsp;</td>
                      <td style="background-color: rgb(102, 153, 255);">&nbsp;</td>

                      <td style="background-color: rgb(102, 204, 255);">&nbsp;</td>
                      <td style="background-color: rgb(102, 255, 255);">&nbsp;</td>
                      <td style="background-color: rgb(153, 0, 255);">&nbsp;</td>
                      <td style="background-color: rgb(153, 51, 255);">&nbsp;</td>
                      <td style="background-color: rgb(153, 102, 255);">&nbsp;</td>
                      <td style="background-color: rgb(153, 153, 255);">&nbsp;</td>
                      <td style="background-color: rgb(153, 204, 255);">&nbsp;</td>
                      <td style="background-color: rgb(153, 255, 255);">&nbsp;</td>
                      <td style="background-color: rgb(204, 0, 255);">&nbsp;</td>

                      <td style="background-color: rgb(204, 51, 255);">&nbsp;</td>
                      <td style="background-color: rgb(204, 102, 255);">&nbsp;</td>
                      <td style="background-color: rgb(204, 153, 255);">&nbsp;</td>
                      <td style="background-color: rgb(204, 204, 255);">&nbsp;</td>
                      <td style="background-color: rgb(204, 255, 255);">&nbsp;</td>
                      <td style="background-color: rgb(255, 0, 255);">&nbsp;</td>
                      <td style="background-color: rgb(255, 51, 255);">&nbsp;</td>
                      <td style="background-color: rgb(255, 102, 255);">&nbsp;</td>
                      <td style="background-color: rgb(255, 153, 255);">&nbsp;</td>

                      <td style="background-color: rgb(255, 204, 255);">&nbsp;</td>
                      <td style="background-color: rgb(255, 255, 255);">&nbsp;</td>
                      <td style="background-color: rgb(115, 115, 115);">&nbsp;</td>
                      </tr>
                      
                </tbody></table>
А вот и скрин
http://pipicek.net/images/bcfe80403188d ... bc4c91.png
Мастерство программирования не в том, что бы писать программы без ошибок,
а в том, что бы писать программы работающие при любом количестве ошибок.

Аватара пользователя
Distructor
Администратор
Сообщения: 1607
Зарегистрирован: 28.12.2009
странно. вечерком поковыряю

Аватара пользователя
Flesh
Сообщения: 16
Зарегистрирован: 23.09.2010
Я заметил этот баг на FireFox и Google Chrome, на Opere и Internet Explore было нормально
Мастерство программирования не в том, что бы писать программы без ошибок,
а в том, что бы писать программы работающие при любом количестве ошибок.

Аватара пользователя
AgentSIB
Сообщения: 329
Зарегистрирован: 17.05.2010
Flesh писал(а): Он выводит RGB цвета типо rgb(211,179,53) а мне нужно что бы вывадило так: #d2b334
Как сделать ?
Самый простой способ ПХП

Код: Выделить всё

function color_to_hex($r,$g,$b){
    return '#'.dechex($r).dechex($g).dechex($b);
}
JS

Код: Выделить всё

function color_to_hex(r,g,b){
    return '#'+r.toString(16)+g.toString(16)+b.toString(16);
}
Frustra fit per plura quod potest fieri per pauciora © Закон "Бритвы Оккама"

Аватара пользователя
Distructor
Администратор
Сообщения: 1607
Зарегистрирован: 28.12.2009
похоже придется применять хак вроде http://www.codeunit.co.za/2010/05/26/co ... zz-to-hex/ т.к. фокс при работе со страницей переводит цвета в rgb и соответственно при запросе цвета и возвращает rgb вместо заданного hex-значения..

Аватара пользователя
Flesh
Сообщения: 16
Зарегистрирован: 23.09.2010
Как его вставить ?
Я JavaScript вообще незнаю

-- добавлено 10 ноя 2010, 22:08 --

Я вот что заменил что если в коде будет написано

Код: Выделить всё

style='background-color:#$color'
То FireFox переводит в RGB, а если будет так

Код: Выделить всё

bgcolor='#$color'
То он оставляет в hex, как это можно использовать ?
Мастерство программирования не в том, что бы писать программы без ошибок,
а в том, что бы писать программы работающие при любом количестве ошибок.

Аватара пользователя
Distructor
Администратор
Сообщения: 1607
Зарегистрирован: 28.12.2009
bgcolor не рекомендуется использовать, т.к. он помечен устаревшим.

Чуть позже вышлю Crank174Rus'у инструкции по устранению ошибки

Аватара пользователя
Flesh
Сообщения: 16
Зарегистрирован: 23.09.2010
ок, я тогда ему напишу.
Мастерство программирования не в том, что бы писать программы без ошибок,
а в том, что бы писать программы работающие при любом количестве ошибок.

Ответить