15 static function get(){
73 function add($tag, $func) {
75 if ( is_callable($func) )
76 $this->custom_codes[$tag] = $func;
88 function remove($tag) {
90 unset($this->custom_codes[$tag]);
105 $this->custom_codes = array();
125 if (empty($this->custom_codes) || !is_array($this->custom_codes))
129 return preg_replace_callback(
"/$pattern/s", array($this,
'doTag'),
$content );
154 $tagnames = array_keys($this->custom_codes);
155 $tagregexp = join(
'|', array_map(
'preg_quote', $tagnames) );
204 if ( $m[1] ==
'[' && $m[6] ==
']' ) {
205 return substr($m[0], 1, -1);
211 if ( isset( $m[5] ) ) {
213 return $m[1] . call_user_func( $this->custom_codes[$tag], $attr, $m[5], $tag ) . $m[6];
216 return $m[1] . call_user_func( $this->custom_codes[$tag], $attr, null, $tag ) . $m[6];
234 $pattern =
'/(\w+)\s*=\s*"([^"]*)"(?:\s|$)|(\w+)\s*=\s*\'([^\']*)\'(?:\s|$)|(\w+)\s*=\s*([^\s\'"]+)(?:\s|$)|"([^"]*)"(?:\s|$)|(\S+)(?:\s|$)/';
235 $text = preg_replace(
"/[\x{00a0}\x{200b}]+/u",
" ", $text);
236 if ( preg_match_all($pattern, $text, $match, PREG_SET_ORDER) ) {
237 foreach ($match as $m) {
239 $atts[strtolower($m[1])] = stripcslashes($m[2]);
241 $atts[strtolower($m[3])] = stripcslashes($m[4]);
243 $atts[strtolower($m[5])] = stripcslashes($m[6]);
244 elseif (isset($m[7]) and strlen($m[7]))
245 $atts[] = stripcslashes($m[7]);
247 $atts[] = stripcslashes($m[8]);
250 $atts = ltrim($text);
272 $atts = (array)$atts;
274 foreach($pairs as $name => $default) {
275 if ( array_key_exists($name, $atts) )
276 $out[$name] = $atts[$name];
278 $out[$name] = $default;
294 if (empty($this->custom_codes) || !is_array($this->custom_codes))
299 return preg_replace_callback(
"/$pattern/s", array($this,
'strip'),
$content );
304 if ( $m[1] ==
'[' && $m[6] ==
']' ) {
305 return substr($m[0], 1, -1);
308 return $m[1] . $m[6];