<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Drowned World &#187; SEO</title>
	<atom:link href="http://www.drownedworld.co.uk/category/seo/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.drownedworld.co.uk</link>
	<description>Same kind of moon, same kind of jungle.</description>
	<lastBuildDate>Sun, 18 Jul 2010 21:09:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Generating an SEO friendly URL in PHP</title>
		<link>http://www.drownedworld.co.uk/2009/08/generating-an-seo-friendly-url-in-php/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://www.drownedworld.co.uk/2009/08/generating-an-seo-friendly-url-in-php/#comments</comments>
		<pubDate>Sun, 02 Aug 2009 17:15:17 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[SEO]]></category>

		<guid isPermaLink="false">http://www.drownedworld.co.uk/?p=74</guid>
		<description><![CDATA[Everyone wants pretty URLs right? Lots of key/pair GET values in URL strings look ugly and are bad for SEO. I was just messing about with a big database table of records that needed converting to SEO friendly urls and &#8230; <a href="http://www.drownedworld.co.uk/2009/08/generating-an-seo-friendly-url-in-php/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Everyone wants pretty URLs right? Lots of key/pair GET values in URL strings look ugly and are bad for SEO. I was just messing about with a big database table of records that needed converting to SEO friendly urls and needed a quick and easy fuction to automate the process. When I need to do a certain job like this I tend to add a static function to a tools class that I keep in my library. I know this isn&#8217;t considered particularly good practice and I should refactor the code out into a url class but for small scripting jobs I&#8217;ve always found this way is a lot more efficient.</p>
<p>First thing we do is take the page name and replace all the spaces with hyphens, then strip out any non-alpha-numeric characters using regex. This will give you a nice URL that will make the  SEO people at your company happy. I&#8217;ve also added a suffix option here that can be used to take care of any duplicates. The logic to handle this should be kept outside this function as it&#8217;s dependent on whatever database table you happen to be using at the time.</p>
<pre>    /**
     * generates an SEO friendly url
     *
     * @param string $name
     * @param interger $suffix
     * @return string
     */
    public static function generateUrl($name, $suffix = 0)
    {

        $alias = str_replace(' ', '-', strtolower(trim($name)));
        $alias = preg_replace('/[^A-Za-z0-9-]/', '', $alias);
        $alias .= ($suffix &gt; 0) ? $suffix : '';

        return $alias;

    }</pre>
<p>By using this function in any admin scripts we can now generate urls for each record by looping through the database.</p>
<p>Eg. If the page title you have is &#8220;This is a new article! Is it helpful?&#8221;, it will be converted to &#8220;this-is-a-new-article-is-it-helpful&#8221;. Perfect for SEO.</p>
<div style='clear:both'></div>]]></content:encoded>
			<wfw:commentRss>http://www.drownedworld.co.uk/2009/08/generating-an-seo-friendly-url-in-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
