Skip to content

Instantly share code, notes, and snippets.

@sdiama
sdiama / highlight.php
Last active May 19, 2020 10:07
HighLight Specific Words in a Phrase
function highlight($sString, $aWords) {
if (!is_array ($aWords) || empty ($aWords) || !is_string ($sString)) {
return false;
}
$sWords = implode ('|', $aWords);
return preg_replace ('@\b('.$sWords.')\b@si', '<strong style="background-color:yellow">$1</strong>', $sString);
}
@sdiama
sdiama / clipboard.js
Created October 20, 2016 04:10
Accessing The Clipboard With JavaScript
var button = document.getElementById("copy-button"),
contentHolder = document.getElementById("content-holder");
button.addEventListener("click", function() {
// We will need a range object and a selection.var range = document.createRange(),
selection = window.getSelection();
// Clear selection from any previous data.
selection.removeAllRanges();
@sdiama
sdiama / jq-disableLinks.js
Last active October 20, 2016 04:07
Disable Links with jQuery