Create a gist now

Instantly share code, notes, and snippets.

anonymous /pi.prime.php
Created Apr 17, 2012

What would you like to do?
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