Clear Field on Focus

<input type="text" onfocus="if(this.value == 'value') { this.value = ''; }" value="value" />

Replace “value” with the default value. If the field is selected, the default value will go away. If the user has previously changed the field value, it’ll be …

Avatar of Chris Coyier
Chris Coyier on

Fix Min/Max-Width for Browsers Without Native Support

This script checks all elements with a class of .fixMinMaxwidth and observes the window. It’s only applied to browsers without native min/max-width support such as ie6 and below. Window resizing won’t be a problem either.

<script type="text/javascript">
//anonymous function to 
Avatar of Chris Coyier
Chris Coyier on

Make HTML5 Elements Work in Old IE

So that the DOM (and thus CSS) recognizes them as real elements:

(function(){if(!/*@cc_on!@*/0)return;var e = "abbr,article,aside,audio,bb,canvas,datagrid,datalist,details,dialog,eventsource,figure,footer,header,hgroup,mark,menu,meter,nav,output,progress,section,time,video".split(','),i=e.length;while(i--){document.createElement(e[i])}})()

Hotlink Script:

<!--[if IE]>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.min.js"></script>
<![endif]-->
Avatar of Chris Coyier
Chris Coyier on (Updated on )

Count Script Excecution Time

$execution_time = microtime(); // Start counting

// Your code

$execution_time = microtime() - $execution_time;
printf('It took %.5f sec', $execution_time);
Avatar of Chris Coyier
Chris Coyier on (Updated on )

Internationalization Language CSS

/*Language-specific*/
:lang(af){quotes:'\201E' '\201D' '\201A' '\2019';}
:lang(ak){font-family:Lucida,"DejaVu Sans",inherit;}
:lang(ar){font-family:Tahoma 12,Nazli,KacstOne,"DejaVu Sans",inherit;}
:lang(bg){quotes:'\201E' '\201C' '\201A' '\2018';}
:lang(bn){font-family:FreeSans,MuktiNarrow,Vrinda,inherit;font-size:1.1em;line-height:1.4em;}
:lang(cs){quotes:'\201E' '\201C' '\201A' '\2018';}
:lang(da){quotes:'\00BB' '\00AB' '\203A' '\2039';}
:lang(de){quotes:'\201E' '\201C' '\201A' '\2018';}
:lang(el){font-family:"DejaVu Sans",inherit;quotes:'\00AB' '\00BB' '\2039' '\203A';}
:lang(en-GB){quotes:'\2018' '\2019' '\201C' '\201D';}
:lang(es){quotes:'\00AB' '\00BB' '\2039' '\203A';}
Avatar of Chris Coyier
Chris Coyier on

PHP Zebra Striping a Table

Table row in a loop:

<!-- Before loop -->
<?php $c = 0; ?>

<!-- Start loop -->
<tr class="<?=($c++%2==1) ? 'odd' : 'even' ?>">
<!-- End loop -->

CSS:

.even { background-color:#FFF; }
.odd { background-color:#666; }
Avatar of Chris Coyier
Chris Coyier on (Updated on )

Simple and Nice Blockquote Styling

The blockquote displays in standards-compliant browsers with the “big quotes before” effect, and in IE with a thick left border and a light grey background.
Unlike other blockquote techniques, this style does not require a nested block-level element (like p). …

Avatar of Chris Coyier
Chris Coyier on (Updated on )

Get Geo-IP Information

Requests a geo-IP-server to check, returns where an IP is located (host, state, country, town).

<?php
       $ip='94.219.40.96';
       print_r(geoCheckIP($ip));
       //Array ( [domain] => dslb-094-219-040-096.pools.arcor-ip.net [country] => DE - Germany [state] => Hessen [town] => Erzhausen )

       //Get an array with geoip-infodata
       
Avatar of Chris Coyier
Chris Coyier on

Convert BR to Newline

Technique #1

function br2newline( $input ) {
     $out = str_replace( "<br>", "\n", $input );
     $out = str_replace( "<br/>", "\n", $out );
     $out = str_replace( "<br />", "\n", $out );
     $out = str_replace( "<BR>", "\n", $out );
     $out = str_replace( "<BR/>", 
Avatar of Chris Coyier
Chris Coyier on (Updated on )

Get All-Time Number of MySQL Queries

<?php
       $handle=@mysql_connect("localhost","root","");

       if (!$handle)
       {
               die("No connection to database");
       }

       echo 'Total number of all-time mysql-queries: '.getTotalNumberOfMySQLQuerys();


       //Returns integer-value of the total number of alltime mysql-calls that have been made
       function getTotalNumberOfMySQLQuerys()
       {
               //global mysql-status containing the number of querys 
Avatar of Chris Coyier
Chris Coyier on (Updated on )

Find Highest Numerically Named File

$latest = getNewest("/path/to/folder/*_bla.xml");

function getNewest($xmlfile){
   foreach (glob($xmlfile) as $filename) {
       $c = explode('_', basename($filename));
       $files[$c[0]] = $filename;
   }
   ksort($files, SORT_NUMERIC);
   $latest = array_pop($files);
   if (file_exists($latest)){
       return $latest;
   }
   return false;
}

In a folder are files named:
1_bla.xml
2_bla.xml
……

Avatar of Chris Coyier
Chris Coyier on