What is a slug ?
A slug is a part of a URL which identifies a particular page on a website in a form readable by users. It’s the nice part of the URL, which explains the page’s content. In WordPress, it’s the editable part of your URL that you can edit when writing a new post.
nSlug allows to create those urls for any language easily.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
use NSlug\SlugGenerator; $options = [ 'limit' => null, 'delimiter' => '-', 'lowercase' => true, ]; $slugGenerator = new SlugGenerator($options); // English strings. echo $slugGenerator->generate('Hello World'); // Prints 'hello-world'. echo $slugGenerator->generate('Life is too short!'); // Prints 'life-is-too-short'. // Arabic strings. echo $slugGenerator->generate('صباح جميل'); // Prints 'صباح-جميل'. echo $slugGenerator->generate('مساء الخير'); // Prints 'مساء-الخير'. |
1 2 3 4 5 6 7 8 9 10 11 |
if( !isset($_SERVER['PHP_AUTH_USER']) ) { if (isset($_SERVER['HTTP_AUTHORIZATION']) && (strlen($_SERVER['HTTP_AUTHORIZATION']) > 0)){ list($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) = explode(':', base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6))); if( strlen($_SERVER['PHP_AUTH_USER']) == 0 || strlen($_SERVER['PHP_AUTH_PW']) == 0 ) { unset($_SERVER['PHP_AUTH_USER']); unset($_SERVER['PHP_AUTH_PW']); } } } |
1 2 3 4 5 |
<IfModule mod_rewrite.c> RewriteEngine On RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L] RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ app.php [QSA,L] </IfModule> |
Underscore.php features a good hundred of methods for all kinds of types : strings, objects, arrays, functions, integers, etc., and provides a parsing class that help switching from one type to the other mid-course.
UriInterface
interface
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
use League\Uri\Parser; $parser = new Parser(); var_export($parser('http://foo.com?@bar.com/')); //returns the following array //array( // 'scheme' => 'http', // 'user' => null, // 'pass' => null, // 'host' => 'foo.com', // 'port' => null, // 'path' => '', // 'query' => '@bar.com/', // 'fragment' => null, //); |
I am currently building a custom slides / template builder for a project, with a lot of moving parts and dynamic logic.
As there are repeating patterns within the slides, each pattern and its logic needs to be neatly separated. As the slides can be reordered and dropzones can be changed, I need to make sure logic doesn’t break and IDs get updated.
Before reassembling all templates, I am making sure that IDs match the slide and dropzone using a preg_replace_callback
One of the patterns is a simple tab setup, each has its unique ID defined like vl-tab_U1_S1_D1.
The function below passes the found matches through to the anonymous callback function in preg_replace_callback and offers outside data to the function using use($foo). The $dropzone object holds the current unit, slide and dropzone of the pattern, which can be used to replace the current ID with the correct one.
1 2 3 4 5 6 7 8 9 10 11 |
$dropzone->region_content = preg_replace_callback('/vl-tab_[^"]++/',function($hit) use($dropzone){ $oldID = explode("_",$hit[0]); $newID = array( "vl-tab", "U".$oldID[1], "S".$dropzone->slide, "D".$dropzone->dropzone ); return implode("_", $newID); },$dropzone->region_content); |
Really nice combo to make magic happen ;)
BTW here a nice website to testdrive and tweak your Regex : https://regex101.com/
„Plates is a native PHP template system that’s fast, easy to use and easy to extend. It’s inspired by the excellent Twig template engine and strives to bring modern template language functionality to native PHP templates.
Plates is designed for developers who prefer to use native PHP templates over compiled template languages, such as Twig or Smarty.“
Voyager is a Laravel Admin Package that includes BREAD(CRUD) operations,
a media manager, menu builder, and much more.
HTML5DOMDocument extends the native DOMDocument library. It fixes some bugs and adds some new functionality.
1 2 3 4 5 6 |
<?php require 'vendor/autoload.php'; $dom = new IvoPetkov\HTML5DOMDocument(); $dom->loadHTML('<!DOCTYPE html><html><body>Hello</body></html>'); echo $dom->saveHTML(); |
A simple Object Oriented wrapper for GitHub API, written with PHP5.
Uses GitHub API v3. The object API is very similar to the RESTful API.
1 2 3 4 5 6 7 |
<?php // This file is generated by Composer require_once 'vendor/autoload.php'; $client = new \Github\Client(); $repositories = $client->api('user')->repositories('ornicar'); |
Paw is a full-featured HTTP client that lets you test the APIs you build or consume. It has a beautiful native OS X interface to compose requests, inspect server responses and generate client code out-of-the-box.
This is one of my go-to tools, when test-driving my API endpoints.