Never been to TextSnippets 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 (or not, you can keep them private!)

About this user

Dan Berlyoung

« Newer Snippets
Older Snippets »
2 total  XML / RSS feed 

State name to 2 letter code

Simple one-trick-pony PHP function to take a state name (case insensitive) and return the 2 letter abbreviation.

        function state_to_twoletter( $state_name ) {
                $state = array();
                $state['AMERICAN SAMOA']='AS';
                $state['DISTRICT OF COLUMBIA']='DC';
                $state['FEDERATED STATES OF MICRONESIA']='FM';
                $state['MARSHALL ISLANDS']='MH';
                $state['NEW HAMPSHIRE']='NH';
                $state['NEW JERSEY']='NJ';
                $state['NEW MEXICO']='NM';
                $state['NEW YORK']='NY';
                $state['NORTH CAROLINA']='NC';
                $state['NORTH DAKOTA']='ND';
                $state['NORTHERN MARIANA ISLANDS']='MP';
                $state['PUERTO RICO']='PR';
                $state['RHODE ISLAND']='RI';
                $state['SOUTH CAROLINA']='SC';
                $state['SOUTH DAKOTA']='SD';
                $state['VIRGIN ISLANDS']='VI';
                $state['WEST VIRGINIA']='WV';
                return $state[strtoupper( $state_name )]; 

Parse out body content from html file in PHP

Parse out the body content of an html file. If no tags found, assume whole file is the content to be used.

        $body_content = join( "", file( $file_to_be_read ) );
        if (eregi( "(.*)", $t, $regs ) ) {
                $body_content = $regs[0];
« Newer Snippets
Older Snippets »
2 total  XML / RSS feed