'\1',
'html' => false
);
$options = array_merge($default, $options);
extract($options);
if (is_array($phrase)) {
$replace = array();
$with = array();
foreach ($phrase as $key => $segment) {
$segment = '(' . preg_quote($segment, '|') . ')';
if ($html) {
$segment = "(?![^<]+>)$segment(?![^<]+>)";
}
$with[] = (is_array($format)) ? $format[$key] : $format;
$replace[] = "|$segment|iu";
}
return preg_replace($replace, $with, $text);
} else {
$phrase = '(' . preg_quote($phrase, '|') . ')';
if ($html) {
$phrase = "(?![^<]+>)$phrase(?![^<]+>)";
}
return preg_replace("|$phrase|iu", $format, $text);
}
}
/**
* Strips given text of all links (]+>|im', '', preg_replace('|<\/a>|im', '', $text));
}
/**
* Adds links (_placeholders = array();
$options += array('escape' => true);
$text = preg_replace_callback(
'#(?)((?:https?|ftp|nntp)://[^\s<>()]+)#i',
array(&$this, '_insertPlaceHolder'),
$text
);
$text = preg_replace_callback(
'#(?)(?_linkUrls($text, $options);
}
/**
* Saves the placeholder for a string, for later use. This gets around double
* escaping content in URL's.
*
* @param array $matches An array of regexp matches.
* @return string Replaced values.
*/
protected function _insertPlaceHolder($matches) {
$key = md5($matches[0]);
$this->_placeholders[$key] = $matches[0];
return $key;
}
/**
* Replace placeholders with links.
*
* @param string $text The text to operate on.
* @param array $htmlOptions The options for the generated links.
* @return string The text with links inserted.
*/
protected function _linkUrls($text, $htmlOptions) {
$replace = array();
foreach ($this->_placeholders as $md5 => $url) {
$link = $url;
if (!preg_match('#^[a-z]+\://#', $url)) {
$url = 'http://' . $url;
}
$replace[$md5] = $this->Html->link($link, $url, $htmlOptions);
}
return strtr($text, $replace);
}
/**
* Links email addresses
*
* @param string $text The text to operate on
* @param array $options An array of options to use for the HTML.
* @return string
* @see TextHelper::autoLinkEmails()
*/
protected function _linkEmails($text, $options) {
$replace = array();
foreach ($this->_placeholders as $md5 => $url) {
$replace[$md5] = $this->Html->link($url, 'mailto:' . $url, $options);
}
return strtr($text, $replace);
}
/**
* Adds email links (