Snippets Code


Latest Php Snippets

Css Snippets

CODE SNIPPETS :: PHP MYSQL JQUERY JAVASCRIPT


10 JQUERY SNIPPETS

Sep 25, 2015   BySARA VIEIRA

jQuery is used on thousands upon thousands of web pages. It’s one of the most common libraries to insert into pages, and it makes DOM manipulation a snap.

Of course, part of jQuery’s popularity is its simplicity. It seems we can do almost anything we like with this powerful library.

For all the options open to us, there are some snippets we tend to come back to time and time again. Today I’d like to give you 10 snippets that everyone, newbies to gurus, will use time and time again.

Full Detail

10 PHP usefull functions for MySQL stuff

Sep 22, 2015   ByGiulio Pons

FUNCTION 1: CONNECT TO A DB

Connect function. I know, everybody already has this function in its library. But I have to add it. The user data are stored in constants, so you don’t have to specify any variable when you call the connect function:

1
2
3
4
5
function connectDb() {
    // connect and set the
    // working db
    if (mysql_connect( DBHOST, DBUSER, DBPWD ) && mysql_select_db( DBNAME )) return true; else return false;
}

FUNCTION 2: RUN SCRIPT FOR REPAIR AND OPTIMIZE TABLES
This function will scan all the tables of a db and run repair and optimize for each table. Usefull, for example, when you want to run a fix on the db every night calling it through a cron job on the server.

Full Detail

10 awesome PHP functions and snippets

Sep 21, 2015   ByJean

Every web developer should keep useful code snippets in a personal library for future reference. Today, I’m showing you the 10 most useful snippets and functions I have added to my snippet library from the past 3 months.

 

Sanitize database inputs

When inserting data in your database, you have to be really careful about SQL injections and other attempts to insert malicious data into the db. The function below is probably the most complete and efficient way to sanitize a string before using it with your database.

function cleanInput($input) {

  $search = array(
    '@<script[^>]*?>.*?@si',   // Strip out javascript
    '@<[/!]*?[^<>]*?>@si',            // Strip out HTML tags
    '@<style[^>]*?>.*?@siU',    // Strip style tags properly
    '@<![sS]*?--[ tnr]*>@'         // Strip multi-line comments
  );

    $output = preg_replace($search, '', $input);
    return $output;
  }
?>
$val) {
            $output[$var] = sanitize($val);
        }
    }
    else {
        if (get_magic_quotes_gpc()) {
            $input = stripslashes($input);
        }
        $input  = cleanInput($input);
        $output = mysql_real_escape_string($input);
    }
    return $output;
}

 

Full Detail

USEFUL LINKS



ESSENTIAL SNIPPETS



Any good web developer knows that re-purposing old code is a big key to getting stuff done efficiently. With each project, I often find myself going back again and again to the same snippets of code. If you’re a beginner, some of these tricks might be new to you. For a seasoned front-end developer, you might already be copy + pasting these from your existing code, or from somewhere else. Either way, these tiny slices of code are great building blocks for most projects. Nothing here is mind-blowing stuff, but it’s always straight-up useful:


Perfect Full-Page Background Images

This one’s a killer for any responsive site. I probably google this one at least once a week:

.cover {
background: url(images/bg.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}

Full-screen images are trendy as all get out right now. This snippet works across any resolution device.
via http://css-tricks.com/perfect-full-page-background-image/

Javascript Function Suicide

This one’s a neat trick for when you want a javascript function to run once and only once, but is triggered by a common event: have it kill itself. Just pop this code into the end of the function, and it’ll over-write itself with function that doesn’t do anything:

var yourFunction = function () {
// do stuff
yourFunction = function() {return false;}
};

Read More
Top