Photo by Anas Alshanti on Unsplash

Code Snippets


_r ( array $array, str $descriptor = '' )

Alias for print_r with nice formatting

Source

DEFINE ( 'PRE', '<pre>' ) ;
DEFINE ( 'NPRE', '</pre>' ) 

function _r ( $array, $descriptor = '' ) {
    if ( $descriptor != '' ) echo '<h5 class="rh5">' . strtoupper($descriptor) . '</h5>' ;
    echo PRE ;
    print_r ( $array ) ;
    echo NPRE ;
}

get_protocol()

checking if protocol is HTTP or HTTPS

Return

String

Source

function get_protocol() {
    if ( isset ( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] != 'off' ) {
    // this is HTTPS
        $protocol = "https";
    } else {
    // this is HTTP
        $protocol = "http";
    }
    return $protocol ;
}

route()

Route of URL, without GET Prameters

Return

String

Source

function route() {
    $route = $_SERVER["REQUEST_URI"] ;
    $pos = strpos ( $route, '?' ) ;
    if (!( $pos === false )) {
        $route = substr ( $route, 0, $pos ) ;
    }
    return $route ;
};

..

$codes = array() ;
foreach ( $icd_codes as $val )  {
    if ( trim($val[0]) != '' ) {
    #   $codes[] = $val[0] ;

        if ( !array_key_exists($val[0], $codes) ) {

            $codes[$val[0]] = $val[1] ;
            echo '<tr>' ;
            echo '<td>' . $val[0] . '</td>' ;
            echo '<td>' . $val[1] . '</td>' ;
            echo '<td>' . '<input type="checkbox" name="H'. $val[0] . '">'    . '</td>' ;
            echo '<td>' . '<input type="checkbox" name="N'. $val[0] . '">'    . '</td>' ;
            echo '<td>' . '<input type="checkbox" name="E'. $val[0] . '">'    . '</td>' ;
            echo '</tr>' ;
        }
    }
}
<button onclick="d_send();">SEND</button>
<div id="diagresult">remote</div><br />
<div id="results">fields</div>
function showValues() {
    var fields = $("#diagnoses").serializeArray();
    $( "#results" ).empty();
    jQuery.each( fields, function( i, field ) {
    $( "#results" ).append( field.name + field.value + " " );
    });
}

$( ":checkbox" ).click( showValues );

function d_send() {
    var s = $("#diagnoses").serialize();
    $("#diagresult").html(s);
}

function showValues() {
    $('#diagnoses :checkbox').prop('checked', false);
    $("input[name='"+this.name+"']").prop('checked', true);
};

$( ":checkbox" ).click( showValues );

function d_send() {
    var s = $("#diagnoses").serialize();

    //  validate

    $("#results").load('/remote/diagnoses/ssp/responder.php', {
        'main' : s,
        'side' : 'side codes'
    });
};

TITLE: Code Snippets
DATE: 2017-12-04
UPDATE:
AUTHOR: jRu
SOURCE:
TAGS:
javascript jquery php