Paper / snippets / regular expressions / functions
php
function nc_fn_trim_number( $_num ) {
return preg_replace("/[^0-9]/","",$_num);
}
function nc_fn_phone( $_label, $_num ) {
return "<strong>$_label:</strong> <a class='cont_number' href='tel:+1" . nc_fn_trim_number( $_num ) . "'>$_num</a><br>";
}
function nc_fn_trim_words( $_string, $_length = 31 ) {
return preg_replace('/\s+?(\S+)?$/', '', substr($_string, 0, $_length ));
}
// trim
function nc_fn_trim_chars( $str, $chars, $end = '...' ) {
if (strlen($str) <= $chars) return $str;
$new = substr($str, 0, $chars + 1);
return substr($new, 0, strrpos($new, ' ')) . $end;
}
js
// get last portion after hash from url
$(this).attr('href').replace(/^.*?(#|$)/,'');
phone numbers
<meta name="format-detection" content="telephone=no">