Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Created April 17, 2012 09:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/2404734 to your computer and use it in GitHub Desktop.
Save anonymous/2404734 to your computer and use it in GitHub Desktop.
Expression Engine Plugin
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Prime {
public function __construct() {
$this->EE =& get_instance();
}
public function no_spaces() {
return str_replace(' ', '', $this->EE->TMPL->tagdata);
}
function format_phone() {
$number = $this->EE->TMPL->tagdata;
$pieces = array();
$result = preg_match('^\(?(?<areacode>[2-9]\d{2})(\)?)(-|.|\s)?(?<prefix>[1-9]\d{2})(-|.|\s)?(?<suffix>\d{4})$^', $number, $pieces);
if($result !== FALSE) {
if(!empty($pieces['areacode']) && !empty($pieces['prefix']) && !empty($pieces['suffix'])) {
return '('.$pieces['areacode'].') '.$pieces['prefix'].'-'.$pieces['suffix'];
}
}
return $number;
}
function strip() {
$allowable = $this->EE->TMPL->fetch_param('allow');
return strip_tags($this->EE->TMPL->tagdata, $allowable);
}
}
/* End of file pi.prime.php */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment