' . $string . ''; $xml = simplexml_load_string($xmlcontent); if (is_object($xml)) { $list = $xml->xpath("//@href"); foreach ($list as $l) { $arr = $l['href']; $urls[] = trim(str_replace('href=', "", str_replace('"', "", $arr->asXML()))); } } else { $regexp = "]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a>"; if (preg_match_all("/$regexp/siU", $string, $matches, PREG_SET_ORDER)) { foreach ($matches as $match) { $urls[] = $match[2]; } } } return $urls; } //We modify the post finding all external urls and shortening them. Then we replace those urls with their respective short urls. function anveto_generateShortUrls($content) { $apikey = get_option('anveto-urlshorternerKey'); $shorteninternal = get_option('anveto-shortenInternalLinks'); $ignore = array("anve.to"); if ($shorteninternal != "internalLinks") { $domain_name = preg_replace('/^www\./', '', $_SERVER['SERVER_NAME']); $ignore[] = $domain_name; } if (strlen($apikey) > 1) { $urls = anveto_getUrls($content); foreach ($urls as $url) { $found = false; foreach ($ignore as $ign) { if (strpos($url, $ign) !== false) { $found = true; } } if (!$found) { $shorturl = anveto_shortenURL($url, $apikey); if (strlen($shorturl) > 1) { $content = str_replace("href=\"".$url, "href=\"".$shorturl, $content); } } } } return $content; } function anveto_shortenerMenu() { add_menu_page('Anve.to URL Shorterner', 'Anve.to', 'administrator', __FILE__, 'anveto_settingsPage', plugins_url('/images/icon.png', __FILE__)); add_action('admin_init', 'Anveto_registerSettings'); } function Anveto_registerSettings() { register_setting('anveto-settingsGroup', 'anveto-urlshorternerKey'); register_setting('anveto-settingsGroup', 'anveto-shortenInternalLinks'); } function anveto_settingsPage() { ?>

Anve.to URL Shorterner

This plugin will automatically create short urls for all of your outgoing links when you create or edit a post. If you have an older post that you would like to shorten your links for then simply edit the post and it should update the links.

Anve.to API Key (Register for a free account)
Also shorten internal urls? />