<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: urls code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Thu, 24 Jul 2008 14:59:41 GMT</pubDate>
    <description>DZone Snippets: urls code</description>
    <item>
      <title>Rewrite input to friendly URL</title>
      <link>http://snippets.dzone.com/posts/show/5629</link>
      <description>// Take an input and rewrite it to a friendly-url-like-this&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;script type="text/javascript"&gt;&lt;br /&gt;&lt;br /&gt;	// Store the current title value&lt;br /&gt;	var title = 'This is a title with a symbol &amp;'&lt;br /&gt;&lt;br /&gt;	// alert(title); // debug&lt;br /&gt;&lt;br /&gt;	// Clean up the title		&lt;br /&gt;	var url = title&lt;br /&gt;		.toLowerCase() // change everything to lowercase&lt;br /&gt;		.replace(/^\s+|\s+$/g, "") // trim leading and trailing spaces		&lt;br /&gt;		.replace(/[_|\s]+/g, "-") // change all spaces and underscores to a hyphen&lt;br /&gt;		.replace(/[^a-z0-9-]+/g, "") // remove all non-alphanumeric characters except the hyphen&lt;br /&gt;		.replace(/[-]+/g, "-") // replace multiple instances of the hyphen with a single instance&lt;br /&gt;		.replace(/^-+|-+$/g, "") // trim leading and trailing hyphens				&lt;br /&gt;		; &lt;br /&gt;	&lt;br /&gt;	alert(url); // outputs 'this-is-a-title-with-a-symbol'&lt;br /&gt;&lt;br /&gt;&lt;/script&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 10 Jun 2008 20:30:06 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5629</guid>
      <author>milkshake (milkshake)</author>
    </item>
    <item>
      <title>Create and lookup tinyurls with PHP</title>
      <link>http://snippets.dzone.com/posts/show/4720</link>
      <description>&lt;code&gt;&lt;br /&gt;        function reverse_tinyurl($url){&lt;br /&gt;            // Resolves a TinyURL.com encoded url to it's source.&lt;br /&gt;            $url = explode('.com/', $url);&lt;br /&gt;            $url = 'http://preview.tinyurl.com/'.$url[1];&lt;br /&gt;            $preview = file_get_contents($url);&lt;br /&gt;            preg_match('/redirecturl" href="(.*)"&gt;/', $preview, $matches);&lt;br /&gt;            return $matches[1];&lt;br /&gt;        }&lt;br /&gt;        &lt;br /&gt;        function tinyurl($url){&lt;br /&gt;        // Shortens a url&lt;br /&gt;            $html = file_get_contents("http://tinyurl.com/create.php?url=".$url);&lt;br /&gt;            preg_match('/http:\/\/preview\.tinyurl\.com\/(.*)&lt;\/b&gt;/', $html, $matches);&lt;br /&gt;            return "http://tinyurl.com/".$matches[1];&lt;br /&gt;        } &lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 31 Oct 2007 05:42:45 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4720</guid>
      <author>logankoester (Logan Koester)</author>
    </item>
    <item>
      <title>Reverse TinyURL</title>
      <link>http://snippets.dzone.com/posts/show/4237</link>
      <description>// Resolves a TinyURL.com encoded url to it's source.&lt;br /&gt;// Example: reverse_tinyurl('http://tinyurl.com/2ocfun') =&gt; "http://logankoester.com"&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;function reverse_tinyurl($url){&lt;br /&gt;	$url = explode('.com/', $url);&lt;br /&gt;	$url = 'http://preview.tinyurl.com/'.$url[1];&lt;br /&gt;	$preview = file_get_contents($url);&lt;br /&gt;	preg_match('/redirecturl" href="(.*)"&gt;/', $preview, $matches);&lt;br /&gt;	return $matches[1];&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 02 Jul 2007 07:04:25 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4237</guid>
      <author>logankoester (Logan Koester)</author>
    </item>
    <item>
      <title>Make anchors from urls and email addresses</title>
      <link>http://snippets.dzone.com/posts/show/617</link>
      <description>This little PHP function will find urls and email addresses in a block of text and turn them into hyperlinks and mailto: anchors respectively.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;function makeLinks($sourceText) {&lt;br /&gt;  $destText = preg_replace( "/([_a-zA-Z0-9-]+)(\.[_a-zA-Z0-9-]+)*@([a-zA-Z0-9-]+)(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,4})/", '&lt;a href="mailto:\\0"&gt;\\0&lt;/a&gt;',$sourceText);&lt;br /&gt;  $destText = preg_replace_callback('/\bhttp[^\s]+/',create_function('$matches', 'return "&lt;a href=\"$matches[0]\"&gt;" . preg_replace("#(\.|/)#", "&amp;shy;$1", $matches[0]) . "&lt;/a&gt;";'),$destText);&lt;br /&gt;  return $destText;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 01 Sep 2005 02:44:51 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/617</guid>
      <author>hjalli (Hjalmar Gislason)</author>
    </item>
    <item>
      <title>Pretty archive URLs in Typo with Routes</title>
      <link>http://snippets.dzone.com/posts/show/31</link>
      <description>Tobi posted this as a new URL scheme for Typo.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;# allow neat perma urls&lt;br /&gt;map.connect 'articles/:year/:month/:day', :controller  =&gt; 'articles', &lt;br /&gt;     :action =&gt; 'find_by_date', &lt;br /&gt;     :year =&gt; /\d{4}/, :day =&gt; nil, :month =&gt; nil&lt;br /&gt;map.connect 'articles/:year/:month/:day/:title', :controller  =&gt; 'articles', &lt;br /&gt;     :action =&gt; 'permalink', :year =&gt; /\d{4}/&lt;/code&gt;</description>
      <pubDate>Sun, 03 Apr 2005 16:41:16 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/31</guid>
      <author>peter (Peter Cooperx)</author>
    </item>
  </channel>
</rss>
