<?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>Indirecthit &#187; PHP</title>
	<atom:link href="http://www.indirecthit.com/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.indirecthit.com</link>
	<description>A Discussion on PHP, AJAX and Other Web Tools with a bit of startup talk</description>
	<lastBuildDate>Tue, 02 Mar 2010 14:34:41 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Media, Cookies &amp; Domains</title>
		<link>http://www.indirecthit.com/2010/03/02/media-cookies-domains/</link>
		<comments>http://www.indirecthit.com/2010/03/02/media-cookies-domains/#comments</comments>
		<pubDate>Tue, 02 Mar 2010 14:34:41 +0000</pubDate>
		<dc:creator>clong</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[cookies]]></category>
		<category><![CDATA[domains]]></category>
		<category><![CDATA[media]]></category>
		<category><![CDATA[static]]></category>

		<guid isPermaLink="false">http://www.indirecthit.com/?p=57</guid>
		<description><![CDATA[With all the brilliant tools (Google Page Speed, YSlow, etc.) out there, web professionals can now easily see a few basic things to improve page speed performance. One suggestion is to send static content from a cookieless domain. On most sites I&#8217;ve worked with, we serve static content from a media subdomain and then the [...]]]></description>
			<content:encoded><![CDATA[<p>With all the brilliant tools (<a title="Google Page Speed" href="http://code.google.com/speed/page-speed/">Google Page Speed</a>, <a title="YSlow" href="http://developer.yahoo.com/yslow/">YSlow</a>, etc.) out there, web professionals can now easily see a few basic things to improve page speed performance. One suggestion is to send static content from a cookieless domain. On most sites I&#8217;ve worked with, we serve static content from a media subdomain and then the real content from the main domain (without www). I know with cookies, if the domain is <strong>.indirecthit.com</strong> it would send that cookie to any subdomain on <strong>indirecthit.com</strong>, therefore the media subdomain would have a cookie. An easy change: remove the <strong>.</strong> from the cookie domain. But when I looked at the <a href="http://www.php.net" class="ubernym uttInitialism" onmouseover="domTT_activate(this, event, 'content', 'PHP: Hypertext Preprocessor' );"><abbr class="uttInitialism">PHP</abbr></a> manual for setcookie, I came across the following statement:</p>
<blockquote><p>The        <em>.</em> is not required but makes it compatible        with more browsers.</p></blockquote>
<p>That doesn&#8217;t sound very good, I want it to be compatible with all browsers&#8230;</p>
<p>I couldn&#8217;t find much on it, from what I did find I believe the reason it doesn&#8217;t work with all browsers is for security. If I had the domain <strong>er.com</strong>, and I set a cookie to the domain <strong>er.com</strong> (notice the missing <strong>.</strong>), the browser could match this with <strong>older.com</strong> or <strong>lesser.com</strong>. If the website at <strong>er.com</strong> set the cookie to <strong>er.com </strong>(without the first <strong>.</strong>), the web server on <strong>older.com </strong>or <strong>lesser.com</strong> can access this cookie&#8230;not good. Therefore, even if I remove the <strong>. </strong>from the domain, it still would match <strong>media.indirecthit.com</strong> and that domain wouldn&#8217;t be cookieless.Doesn&#8217;t solve my problem and isn&#8217;t compatible with most browsers.</p>
<p>The solution, is to split out your media server on a different domain such as <strong>indirecthitmedia.com</strong>. This is why when you visit some Google properties it loads media content from <strong>gstatic.com </strong>not<strong> media.google.com</strong> or <strong>google.com</strong>. And obviously you don&#8217;t set any cookies to this new media domain. You will now score a bit higher on <a title="Google Page Speed" href="http://code.google.com/speed/page-speed/">Google Page Speed</a> and <a title="YSlow" href="http://developer.yahoo.com/yslow/">YSlow</a>. Congrats!</p>]]></content:encoded>
			<wfw:commentRss>http://www.indirecthit.com/2010/03/02/media-cookies-domains/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google Did you Mean on Search Pages Using PHP 4</title>
		<link>http://www.indirecthit.com/2007/08/24/google-did-you-mean-on-search-pages-using-php-4/</link>
		<comments>http://www.indirecthit.com/2007/08/24/google-did-you-mean-on-search-pages-using-php-4/#comments</comments>
		<pubDate>Fri, 24 Aug 2007 15:48:03 +0000</pubDate>
		<dc:creator>clong</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[aspell]]></category>
		<category><![CDATA[did you mean]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[search]]></category>
		<category><![CDATA[spellcheck]]></category>

		<guid isPermaLink="false">http://www.indirecthit.com/2007/08/24/google-did-you-mean-on-search-pages-using-php-4/</guid>
		<description><![CDATA[What&#8217;s the best way to handle did you mean? It&#8217;s one of the greatest features of Google, I never worry about misspelling search terms because I know Google will always show the error of my ways.
On Well.ca we had previously implemented this feature using Levenshtein, this measures the number of permutations to get from one [...]]]></description>
			<content:encoded><![CDATA[<p>What&#8217;s the best way to handle did you mean? It&#8217;s one of the greatest features of Google, I never worry about misspelling search terms because I know Google will always show the error of my ways.</p>
<p>On <a href="http://www.well.ca" class="ubernym uttJustLink" onmouseover="domTT_activate(this, event, 'content', 'An online health store, the place I work.','caption', 'Well.ca' );">Well.ca</a> we had previously implemented this feature using <a href="http://ca.php.net/levenshtein">Levenshtein</a>, this measures the number of permutations to get from one string to another. The problem with this is that we had the search term &#8220;Obus&#8221; being corrected to &#8220;Burt&#8217;s&#8221;, not exactly the most accurate system. As a result, I&#8217;ve been working with using Pspell/Aspell to handle the &#8220;Did you mean&#8221;. Aspell is a very popular spell checking software, you can find it used in almost any OS application requiring spell checking. <a href="http://www.php.net" class="ubernym uttInitialism" onmouseover="domTT_activate(this, event, 'content', 'PHP: Hypertext Preprocessor' );"><abbr class="uttInitialism">PHP</abbr></a> interfaces with Aspell through Pspell.</p>
<p>One of the requirements we have, is that we want Pspell/Aspell to use a custom dictionary. Being an Ecommerce site, we want the dictionary to consist of brands, product names, categories, and product subtitles. A limitation of Pspell is that it does not allow you to use just a personal dictionary, therefore, I went through the process of creating a custom language dictionary for Pspell/Aspell to use. I have described all the steps below, from the initial install to the actual checking.</p>
<p><span id="more-8"></span></p>
<p><strong>Installing:</strong></p>
<p><em>Note: These are the following steps I used to install Aspell/Pspell on my Macbook Pro running the latest version of OS X. They should work fine for Linux/Unix systems, for Windows there are other resources on the web for installing these tools.</em></p>
<ol>
<li><em>Install Aspell &#8211; </em>Install Aspell using your package manager (I use MacPorts) or from the Aspell website.</li>
<li><em>Compile <a href="http://www.php.net" class="ubernym uttInitialism" onmouseover="domTT_activate(this, event, 'content', 'PHP: Hypertext Preprocessor' );"><abbr class="uttInitialism">PHP</abbr></a> w/ PSpell support </em>
<ol>
<li>First check to see if your <a href="http://www.php.net" class="ubernym uttInitialism" onmouseover="domTT_activate(this, event, 'content', 'PHP: Hypertext Preprocessor' );"><abbr class="uttInitialism">PHP</abbr></a> install already is built w/ Pspell (look at the output of php_info() for the configure flag &#8211;with-pspell)</li>
<li>(If you are using MacPorts look at the bullet below) If not, compile <a href="http://www.php.net" class="ubernym uttInitialism" onmouseover="domTT_activate(this, event, 'content', 'PHP: Hypertext Preprocessor' );"><abbr class="uttInitialism">PHP</abbr></a> with all the options you want including &#8220;&#8211;with-pspell={prefix}&#8221;. Where prefix is the location of your lib and include containing Pspell.
<ul>
<li>If you are using MacPorts, you can add the flag to the Portfile. On my computer, the Portfile was located at &#8220;<em>/opt/local/var/macports/sources/ rsync.macports.org/release/ports /www/php4/Portfile&#8221;. </em>Open that file and add &#8220;&#8211;with-pspell=${prefix}&#8221; to configure.args. You can then uninstall PHP4 and reinstall it, it should now use the modified Portfile to compile <a href="http://www.php.net" class="ubernym uttInitialism" onmouseover="domTT_activate(this, event, 'content', 'PHP: Hypertext Preprocessor' );"><abbr class="uttInitialism">PHP</abbr></a>.</li>
</ul>
</li>
<li>Restart Apache, and check your php_info() for the proper flags.</li>
</ol>
</li>
<li>You should now be capable of using pspell in <a href="http://www.php.net" class="ubernym uttInitialism" onmouseover="domTT_activate(this, event, 'content', 'PHP: Hypertext Preprocessor' );"><abbr class="uttInitialism">PHP</abbr></a>.</li>
</ol>
<p><!--more--><br />
<strong>Creating a Custom Language Dictionary</strong></p>
<p><em>Note: If you don&#8217;t need a custom language dictionary, you can skip straight to the creating &#8220;Did you mean&#8221; section.</em></p>
<ol>
<li> Download the aspell-lang package:<br />
[code]cvs -z3 -d:pserver:anonymous@cvs.savannah.gnu.org:/sources/aspell co aspell-lang[/code]<br />
The remainder of the steps are now based off of the <a href="http://cvs.savannah.gnu.org/viewvc/aspell-lang/README?revision=1.2&amp;root=aspell&amp;view=markup">README</a> file</li>
<li>Head into the aspell-lang directory. Aspell-lang comes with a command for creating the files used to create a new custom dictionary. The command to create these files is:<br />
[code]./pre {lang_name} {char_set}[/code]</p>
<ul>
<li><em>lang_name</em> must follow the ISO language standards. At the simplest, two alphabetical characters.</li>
<li><em>char_set</em> aspell can use a variety of character sets. See the README for a list of them. For English, I used iso-8859-1</li>
<li>The command I used was: ./pre we iso-8859-1</li>
</ul>
</li>
<li>You should now have a directory called the language name selected. CD into that directory.</li>
<li>At this point, you can edit the info file or leave it at the default. It is fairly self explanatory.</li>
<li>You can now create the wordlist in the file {lang_name}.wl. The format is one word per line.</li>
<li>By default, aspell does not allow any non-alphabetical characters in words. To allow other characters you need to modify {lang_name}.dat
<ul>
<li>The line you need to modify starts with <em>special</em>, you might need to uncomment it.</li>
<li>The format of the special line is: <em>special {char} {start}{middle}{end}</em>. <em>char</em> is the character to be included. <em>start, middle, end</em> tells Aspell where the character is allowed. &#8216;*&#8217; means the character is allowed, &#8216;-&#8217; means the character is not.</li>
<li>An example special attribute is <em>&#8216; -*-</em>, the character is <em>&#8216;</em>, and it is not allowed as the first or last character of the word but is allowed in the middle of the word.</li>
</ul>
</li>
<li>When the wordlist is finalized, you need to run the following commands:

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>proc
.<span style="color: #000000; font-weight: bold;">/</span>configure
<span style="color: #c20cb9; font-weight: bold;">make</span>
<span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

</li>
<li>Ignoring any problems, you should now have a custom dictionary installed.</li>
</ol>
<p><!--more--><br />
<strong>Creating &#8220;Did you mean&#8221;</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//Split the search string by spaces</span>
<span style="color: #000088;">$keywords_single</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">' '</span><span style="color: #339933;">,</span> <span style="color: #000088;">$keywords_string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//Get the number of words they are searching by</span>
<span style="color: #000088;">$sizeof_keywords_single</span> <span style="color: #339933;">=</span> <span style="color: #990000;">sizeof</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$keywords_single</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pspell_config</span> <span style="color: #339933;">=</span> pspell_config_create<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;we&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pspell_link</span> <span style="color: #339933;">=</span> pspell_new_config<span style="color: #009900;">&#40;</span><span style="color: #000088;">$pspell_config</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$keywords_single_replacement</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Create the replacement array</span>
<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> <span style="color: #000088;">$sizeof_keywords_single</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">//Loop through the words</span>
	<span style="color: #666666; font-style: italic;">//Check if the word is correctly spelt</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>pspell_check<span style="color: #009900;">&#40;</span><span style="color: #000088;">$pspell_link</span><span style="color: #339933;">,</span> <span style="color: #000088;">$keywords_single</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$keywords_misspell</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">//Get the suggestions from Pspell</span>
		<span style="color: #000088;">$suggestions</span> <span style="color: #339933;">=</span> pspell_suggest<span style="color: #009900;">&#40;</span><span style="color: #000088;">$pspell_link</span><span style="color: #339933;">,</span> <span style="color: #000088;">$keywords_single</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">//Take the first result (Pspell sorts the result)</span>
		<span style="color: #000088;">$keywords_single_replacement</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$suggestions</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">//Set the replacement word back to the original word</span>
		<span style="color: #000088;">$keywords_single_replacement</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$keywords_single</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;">/*
 * The following code replaces the words with the corrected words above.
 */</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$keywords_phrase</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$keywords_misspell</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$keywords_replacement</span> <span style="color: #339933;">=</span> <span style="color: #990000;">stripslashes</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'keyword'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> <span style="color: #000088;">$sizeof_keywords_single</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$keywords_replacement</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span>
					<span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'#(?!&amp;lt;.*?)(%s)(?![^&amp;lt;&amp;gt;]*?&amp;gt;)#i'</span><span style="color: #339933;">,</span>
					<span style="color: #990000;">preg_quote</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$keywords_single</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
					<span style="color: #000088;">$keywords_single_replacement</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
					<span style="color: #000088;">$keywords_replacement</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;">//You can now print the Did You Mean $keywords_replacement...</span>
?<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><!--more--></p>
<p><strong>Resources</strong></p>
<ul>
<li>Pspell Manual &#8211; http://www.php.net/manual/en/ref.pspell.php</li>
<li>Aspell Website &#8211; http://aspell.net/</li>
</ul>]]></content:encoded>
			<wfw:commentRss>http://www.indirecthit.com/2007/08/24/google-did-you-mean-on-search-pages-using-php-4/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
