Skip to content

Instantly share code, notes, and snippets.

@giventofly
giventofly / youtube_id_regex.php
Created July 7, 2022 12:44 — forked from ghalusa/youtube_id_regex.php
Extract the YouTube Video ID from a URL in PHP
<?php
// Here is a sample of the URLs this regex matches: (there can be more content after the given URL that will be ignored)
// http://youtu.be/dQw4w9WgXcQ
// http://www.youtube.com/embed/dQw4w9WgXcQ
// http://www.youtube.com/watch?v=dQw4w9WgXcQ
// http://www.youtube.com/?v=dQw4w9WgXcQ
// http://www.youtube.com/v/dQw4w9WgXcQ
// http://www.youtube.com/e/dQw4w9WgXcQ
// http://www.youtube.com/user/username#p/u/11/dQw4w9WgXcQ
const makeRequest = async () => {
try {
// this parse may fail
const data = JSON.parse(await getJSON())
console.log(data)
} catch (err) {
console.log(err)
}
}
@giventofly
giventofly / nl2p.php
Last active August 5, 2019 09:17
Simple nl2p (wraps things in paragraph tags as opposed to line breaks - nl2br)
<?php
/**
* This wraps blocks of text (delimited by \n) in p tags (similar to nl2br)
* @author Scott Dover <sdover102@gmail.com>
* @param str
* @return str
*/
function nl2p($string) {
/* Explode based on new-line */
@giventofly
giventofly / wp-automated-cache-busting.php
Last active December 26, 2018 16:57 — forked from kjbrum/wp-automated-cache-busting.php
Wordpress auto Cache clear. This works by adding the file's change time to the end of the URL (last argument of the call)
<?php
/* For Themes */
wp_enqueue_style('slug', get_template_directory_uri().'/css/slug.css', array(), filemtime(get_template_directory().'/css/slug.css'));
wp_enqueue_script('slug', get_template_directory_uri().'/js/slug.js', array(), filemtime(get_template_directory().'/js/slug.js'));
/* For Plugins */
wp_enqueue_style('slug', plugin_dir_url(__FILE__).'css/slug.css', array(), filemtime(plugin_dir_path(__FILE__).'css/slug.css'));
wp_enqueue_script('slug', plugin_dir_url(__FILE__).'js/slug.js', array(), filemtime(plugin_dir_path(__FILE__).'js/slug.js'));