neemzy's snippets - Page 5 of 5

...which make them wrap <a> tags around it and gently break your design !

<meta name="format-detection" content="telephone=no" />

Pretty useful if you can't achieve your aims with pure portrait/landscape media queries !

window.onorientationchange = function()  {
    // Your code here

This allows you to call specific stylesheets for WebKit browsers (Chrome, Safari...) and Opera

<!--[if !IE]><!-->
    <link rel="stylesheet" href="css/webkit.css" media="screen and (-webkit-min-device-pixel-ratio: 0)" />

    <!-- Legacy : this worked until version 12 -->
    <link rel="stylesheet" href="css/opera.css" media="not screen and (1)" />

    <!-- This shouldn't be needed anyway since Opera is going to use WebKit as well -->
        if (window.opera)
            document.write('<link rel="stylesheet" href="css/opera.css" />');

This code helps you set up a video tag that will adapt its size to its container's.

<video preload="auto" controls="controls" style="width: 100%; max-width: 100%; height: auto;">
    <source src="media.mp4" />
    <source src="media.ogv" />
    <object width="640" height="480" type="application/x-shockwave-flash" data="media.swf">
        <param name="movie" value="media.swf" />
        <param name="wmode" value="transparent" />
        <img src="media.jpg" alt="Y U NO READ ANYTHING!?" />

To deal with the lack of this function in jQuery (read-only version).

jQuery.fn.outer = function() { return jQuery(jQuery('<div></div>').html(this.clone())).html(); }

This function takes a string as its first parameter and as many integers as you want as the next one(s), and returns an array with the string exploded at the index(es) you specified

function explodex() {
    $args = func_get_args();
    if (!is_string($args[0])) return false;
    $array = array();
    $lastpos = 0;
    for ($i=1;$i<func_num_args();$i++) {
        if (!is_int($args[$i])) return false;
        $tmp = substr($args[0], $lastpos, $args[$i] - $lastpos);
        if ($tmp != '') $array[] = $tmp;
        $lastpos = $args[$i];
    $tmp = substr($args[0], $lastpos);
    if ($tmp != '') $array[] = $tmp;
    return $array;

Use this if you're stuck on an old version of PHP

function rstrstr($haystack, $needle) {
    $idx = strrpos($haystack, $needle);
    if ($idx !== false) $haystack = substr($haystack, 0, $idx);
    return $haystack;

This is how you check if you can use the browser's implementation of new HTML5 input types (just like Modernizr & co.)

function testInputSupport(type) {
    var i = document.createElement('input');
    i.setAttribute('type', type);
    return i.type !== 'text';

Check if your users are allowed to access a certain document, or whatever...

RewriteRule ^mydoc.pdf$ mydoc-pdf.php

    if ($myCondition) {
        // headers and stuff
    else // ...

Quick way to invert the value of a boolean field in SQL (switching 0/1)

UPDATE users SET is_admin = (1 - is_admin) WHERE [...]