#snippets
11 posts tagged snippets. Clear filter
-
How to Extract Time Information from a Natural Language String with a Regular Expression and PHP
You can easily extract time information from a string with a regular expression and PHP (or any language with regular expressions). $str = "Here is how to extract time info.. like 4:30 PM and 2:10...
-
How to Parse Query Strings in PHP
Here is a quick snippet for parsing query strings in PHP. You can use the parseurl and parsestr methods. parsestr will create a variable for you populated with results. $url =...
-
PHP Headers for Sending CSV File Downloads
If you would like to force a file download prompt to the user, instead of just outputting the text to the browser, use the following headers. <?php $filename = "some-filename";...
-
How to Calculate Age with PHP
Calculate age in PHP $yourbirthday = '1982-08-29'; $difference = datediff(datecreate(), datecreate($yourbirthday)); $age = $difference-format('%Y'); // 35 Short and sweet
-
How to Slugify a String in PHP
Here is a snippet for generating a URL friendly slug in PHP function slugify($string){ return strtolower(trim(pregreplace('/[^A-Za-z0-9-]+/', '-', $string), '-')); } And you can use it in your code...
-
How to Generate a UUID in PHP 7
Here is a little snippet for generating a UUID in PHP 7 function uuid(){ $data = randombytes(16); $data[6] = chr(ord($data[6]) & 0x0f | 0x40); $data[8] = chr(ord($data[8]) & 0x3f | 0x80); return...
-
Matching email addresses in Javascript
Matching email addresses in Javascript regex = /\b[a-zA-Z0-9.%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}\b/img "hello sean@example.com how are you? do you know bob@example.com?".match(regex) // =...
-
Find a File On Your File System with the Unix Find Command By Extension
find path/ -name .txt
-
A Couple of Usefule Snippets When Working with Textmate
Here is the snippet f path/to/directory 'search string' | open\in\mate This snippet (technically 2 snippets) will recursively scan the contents of files in a directory and then open all the files...
-
How to Split a Large File Into Smaller Files on OSX or Unix
Use the split command. You can set the number of lines (the "-l" flag) to split on and also the location of where the split files should be saved. Note, the output directory must already exists.
-
How to Create a Date Time Snippet in Sublime Text 2 (Dynamic Signature with Time Stamp)
You'll have to create a new plugin. From the menu bar select Tools New Plugin Copy the Python script from the signature.py file. Remember to replace your email address (it's example.com). Save the...