Skip to content

Commit

Permalink
Move HTML to a separate file.
Browse files Browse the repository at this point in the history
  • Loading branch information
dotancohen committed Jul 17, 2013
1 parent 93ecc42 commit 7ca07ec
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 28 deletions.
33 changes: 33 additions & 0 deletions html.php
@@ -0,0 +1,33 @@
<?php



/**
* Output the <options> of a select statement and optionally preselect one
*
* @author Dotan Cohen
* @version 2013-06-30
*
* @param array $data Associative array to be converted to <options>
* @param string $quote_char Character to use to quote values. Must be " or '
* @param string $selected Default value to select
*
* @return TRUE
*/
function output_select_options($data, $quote_char='"', $selected=NULL)
{
if ( !is_array($data) || !in_array($quote_char, array('"', "'")) ) {
return NULL;
}

foreach ( $data as $f=>$v) {
$s = $f==$selected ? " selected={$quote_char}selected{$quote_char}" : '';
echo "<option value={$quote_char}{$f}{$quote_char}{$s}>{$v}</option>";
}

return TRUE;
}



?>
28 changes: 0 additions & 28 deletions util.php
Expand Up @@ -238,32 +238,4 @@ function get_typical_results($input)



/**
* Output the <options> of a select statement and optionally preselect one
*
* @author Dotan Cohen
* @version 2013-06-30
*
* @param array $data Associative array to be converted to <options>
* @param string $quote_char Character to use to quote values. Must be " or '
* @param string $selected Default value to select
*
* @return TRUE
*/
function output_select_options($data, $quote_char='"', $selected=NULL)
{
if ( !is_array($data) || !in_array($quote_char, array('"', "'")) ) {
return NULL;
}

foreach ( $data as $f=>$v) {
$s = $f==$selected ? " selected={$quote_char}selected{$quote_char}" : '';
echo "<option value={$quote_char}{$f}{$quote_char}{$s}>{$v}</option>";
}

return TRUE;
}



?>

0 comments on commit 7ca07ec

Please sign in to comment.