Skip to content
View in the app

A better way to browse. Learn more.

The Daily Neopets Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

dynamic color selector

Featured Replies

I was trying to create a dynamic color selector using php....

 

I uploaded it here: http://www.theneopianoutpost.com/new/index.php

I get this error: Parse error: parse error, unexpected T_STRING in /home/content/I/n/d/Individual12/html/new/index.php on line 29

 

Heres my coding: (Note: Do not try to figure this out if you don't know php or else you'll hurt your head :P)

<?php
function hsb( $h, $s, $v )
{
 $r = $g = $b =0;
 if ( $s==0 )
 {
$r = $g = $b =$v;
 }
 else
 {
$h = $h / 60;
$i = floor( $h );
$f = $h - $i;
$p = $v * ( 1 - $s );
$q = $v * ( 1 - $s * $f );
$t = $v * ( 1 - $s * ( 1 - $f ) );
switch( $i ) {
case o: $r = $v; $g = $t; $b = $p; break;
case 1: $r = $q; $g = $v; $b = $p; break;
case 2: $r = $p; $g = $v; $b = $t; break;
case 3: $r = $p; $g = $q; $b = $v; break;
case 4: $r = $t; $g = $p; $b = $v; break;
default: $r = $v; $g = $p; $b = $q; break;
}
 }
 return array( $r, $g, $b );
}

functiom hsb2hex( $h, $s, $b )
{
  list( $r, $g, $b ) = hsb( $h, $s, $b );
  return sprintf( "#%02x%02x%02x", $r, $g, $b );
}
?>
<html>
<head>
<script language="Javascript">
function mover( id )
{
 var obj = document.getElementById( id );
 obj.style.borderColor = "white";
}
function mout( id )
{
 var obj = document.getElementById( id );
 obj.style.borderColor = "black";
}
function selectColor( color )
{
 document.getElementById( "hoverColor" ).innerHTML = color;
}
</script>
<style type="text/css">
body { font family: arial, verdana, sans-serif; }
#color { font-family: courier }
#hoverColor { font-family: courier; }
</style>
</head>
<body>
Color: <input id="color" type="text" size="8" />
<table cellspacing="10" cellpadding="0"><tr><td>
<table cellspacing="0" cellpadding="0">
<?php
$id = 1;
for( $h = 0; $h < 360; $h += 18 ) { ?>
<tr>
<?php for( $b = 255; $b >= 0; $b -= 10 ) {
$color = hsb2hex( $h, $b / 255, $b );
?>
<td>
<div id="cp<?php echo( $id ); ?>" style="height:10px; width:10px; border: 1px solid white; background:<?php echo( $color ); ?>;" onmouseover="mover('cp<?php echo( $id ); ?>');hover('<?php echo( $color ); ?>');" onmouseout="mout('cp<?php echo( $id ); ?>')" onclick="selectColor('<?php echo( $color ); ?>');"</div>
</td>
<?php
$id += 1;
} ?>
</tr>
<?php } ?>
</table>
</td><td valign="top">
<div id="hoverColor"></div>
</td></tr></table>
</body>
</html>

 

Any ideas why its not working?

 

Thanks.....and good luck! :yes:

Error on line 29...

 

which is :

 

functiom hsb2hex( $h, $s, $b )

 

and should be

 

function hsb2hex( $h, $s, $b )

 

so just a typing error, I think...

  • 2 weeks later...
  • Author

I write my php on notepad and use SmartFTP to upload it...

 

D'oh! Thanks for the help Angelxepha! ((stupid typo <_<))

You are welcome Zac :P

 

And usually, well, I dont code much in PHP... but I would do it in notepad or viewing source code in dreamweaver...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.