Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Nathan Carnes

« Newer Snippets
Older Snippets »
Showing 1-5 of 5 total  RSS 

PHP Select Form Helper

// takes an array of values and a value to match, and outputs formatted <option>s with the <option> matching $match selected
// must be manually wrapped in <select></select to allow for maximum flexibility

function selectHelper($values, $match)
{
  $keys = array_keys($values);
  $i = 0;
	
  foreach($values as $option)
  {
    $selected = null;
		
    if($match == $keys[$i])
      $selected = " selected";
			
    echo "	<option value=\"".$keys[$i]."\"$selected>".$option."</option>\n";
		
    $i++;
  }
}

//sample usage:
$values = array(
  "lb" => "Pounds",
  "ea" => "Each",
  "oz" => "Ounces");
				
  selectHelper($values, $product->unit);

Favicon discovery

<link rel="shortcut icon" href="favicon.ico" />

Object alternative to iframe for XHTML 1.0 strict

<object data="mypage.php" type="text/html"></object>

RSS/Atom Autodiscovery

// description of your code here

<link rel="alternate" type="application/rss+xml" title="RSS Feed" href="rss.xml" />

<!-- or... //-->

<link rel="alternate" type="application/atom+xml" title="Atom Feed" href="Atom.xml" />

jQuery onLoad alternative

// faster jQuery-based document.onLoad alternative

$(document).ready(function() {
   // put all your jQuery goodness in here.
   });
« Newer Snippets
Older Snippets »
Showing 1-5 of 5 total  RSS