<?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>URL &#8211; stoimen&#039;s web log</title>
	<atom:link href="/tag/url/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>on web development</description>
	<lastBuildDate>Tue, 13 Feb 2018 08:18:15 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.0.3</generator>
	<item>
		<title>PHP: Fetch $_GET as String with http_build_query()</title>
		<link>/2011/08/17/php-fetch-get-as-string-with-http_build_query/</link>
		<comments>/2011/08/17/php-fetch-get-as-string-with-http_build_query/#comments</comments>
		<pubDate>Wed, 17 Aug 2011 07:42:24 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[D]]></category>
		<category><![CDATA[elegant solution]]></category>
		<category><![CDATA[Foreach]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[http_build_query]]></category>
		<category><![CDATA[php reference]]></category>
		<category><![CDATA[Query string]]></category>
		<category><![CDATA[Scripting languages]]></category>
		<category><![CDATA[String]]></category>
		<category><![CDATA[URL]]></category>
		<category><![CDATA[World Wide Web]]></category>

		<guid isPermaLink="false">/?p=2358</guid>
		<description><![CDATA[PHP is really full of functions for everything! Most of the time when you try to do something with strings, there&#8217;s a function that can do it better and faster. The Route from $_GET to String The global arrays in PHP contain request parameters. Either GET or POST. As you know if the page address &#8230; <a href="/2011/08/17/php-fetch-get-as-string-with-http_build_query/" class="more-link">Continue reading <span class="screen-reader-text">PHP: Fetch $_GET as String with http_build_query()</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2011/08/18/powerful-php-less-known-string-manipulation/" rel="bookmark" title="Powerful PHP: Less Known String Manipulation">Powerful PHP: Less Known String Manipulation </a></li>
<li><a href="/2010/06/16/zend-examples-get-parameters-default-value/" rel="bookmark" title="Zend Examples: GET Parameters Default Value">Zend Examples: GET Parameters Default Value </a></li>
<li><a href="/2010/09/17/5-php-string-functions-you-need-to-know/" rel="bookmark" title="5 PHP String Functions You Need to Know">5 PHP String Functions You Need to Know </a></li>
<li><a href="/2010/09/08/http-post-with-php-without-curl/" rel="bookmark" title="HTTP POST with PHP without cURL">HTTP POST with PHP without cURL </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p><strong>PHP</strong> is really full of functions for everything! Most of the time when you try to do something with strings, there&#8217;s a function that can do it better and faster. </p>
<h2>
The Route from $_GET to String<br />
</h2>
<p>The global arrays in PHP contain request parameters. Either <a href="http://php.net/manual/en/reserved.variables.get.php" title="PHP: $_GET - Manual" target="_blank">GET</a> or <a href="http://www.php.net/manual/en/reserved.variables.post.php" title="PHP: $_POST - Manual" target="_blank">POST</a>. As you know if the page address is something like:</p>
<pre lang="PHP">
http://www.example.com/index.php?a=b&key=value
</pre>
<p>This means that you pass to the index.php file two parameters &#8211; &#8220;a&#8221; and &#8220;key&#8221; with their values: &#8220;b&#8221; and &#8220;value&#8221;. Now in this case you can dump the $_GET <strong>global array</strong> somewhere in index.php and you&#8217;ll receive something like this.</p>
<pre lang="PHP">
array(
	"a"   => "b",
	"key" => "value",
);
</pre>
<p>This is however pseudocode, but in fact $_GET will be very similar to this sample array. <span id="more-2358"></span></p>
<h2>
$_GET to String<br />
</h2>
<p>Very often when a developer need to process the $_GET array to a string, which means generating again the query string from $_GET, he often comes to some operation like this one.</p>
<pre lang="PHP">
$queryString = '';
foreach ($_GET as $key => $value) {
	$queryString .= $key . '=' . $value . '&';
}
</pre>
<p>However this will result in something quite ugly like <b>a=b&#038;key=value&#038;</b> which comes with a trailing &#038; at the end of the string.</p>
<p>There is however another approach &#8211; using an array.</p>
<pre lang="PHP">
$queryString = array();
foreach ($_GET as $key => $value) {
	$queryString[] = $key . '=' . $value;
}
$queryString = implode('&', $queryString);
</pre>
<p>But that invokes one function more and this is still not the most elegant solution. As I said at the beginning PHP is full of useful functions and here comes the <a href="http://php.net/manual/en/function.http-build-query.php" title="PHP: http_build_query - Manual" target="_blank">http_build_query</a>.</p>
<h2>
http_build_query<br />
</h2>
<p>This is exactly what you need. As it name describe you can build the query string even by using a different from &#038; separator.</p>
<pre lang="PHP">
$queryString = http_build_query($_GET, '', '|');
</pre>
<p>Thus $queryString will contain <strong>a=b|key=value</strong> and at least the code will look pritier.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2011/08/18/powerful-php-less-known-string-manipulation/" rel="bookmark" title="Powerful PHP: Less Known String Manipulation">Powerful PHP: Less Known String Manipulation </a></li>
<li><a href="/2010/06/16/zend-examples-get-parameters-default-value/" rel="bookmark" title="Zend Examples: GET Parameters Default Value">Zend Examples: GET Parameters Default Value </a></li>
<li><a href="/2010/09/17/5-php-string-functions-you-need-to-know/" rel="bookmark" title="5 PHP String Functions You Need to Know">5 PHP String Functions You Need to Know </a></li>
<li><a href="/2010/09/08/http-post-with-php-without-curl/" rel="bookmark" title="HTTP POST with PHP without cURL">HTTP POST with PHP without cURL </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2011/08/17/php-fetch-get-as-string-with-http_build_query/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Redirect with Zend Framework</title>
		<link>/2010/06/21/redirect-with-zend-framework/</link>
		<comments>/2010/06/21/redirect-with-zend-framework/#comments</comments>
		<pubDate>Mon, 21 Jun 2010 14:31:10 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[zend framework]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[PHP programming language]]></category>
		<category><![CDATA[redirect]]></category>
		<category><![CDATA[referer]]></category>
		<category><![CDATA[URL]]></category>
		<category><![CDATA[Web application frameworks]]></category>
		<category><![CDATA[World Wide Web]]></category>
		<category><![CDATA[zend]]></category>

		<guid isPermaLink="false">/?p=1652</guid>
		<description><![CDATA[Once I wrote about redirecting with Zend Framework, but what I missed back than was a common mistake. Although the code from my post is working, to be completely correct after redirecting I&#8217;d to add an exit() statement. This is important because the header is changed and if something goes after the redirect there will &#8230; <a href="/2010/06/21/redirect-with-zend-framework/" class="more-link">Continue reading <span class="screen-reader-text">Redirect with Zend Framework</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2009/11/27/redirecting-with-zend-framework/" rel="bookmark" title="Redirecting with Zend Framework">Redirecting with Zend Framework </a></li>
<li><a href="/2010/05/25/download-files-with-zend-framework/" rel="bookmark" title="Download Files with Zend Framework">Download Files with Zend Framework </a></li>
<li><a href="/2009/12/20/redirecting-with-zend-framework-part-2/" rel="bookmark" title="Redirecting with Zend Framework &#8211; part 2">Redirecting with Zend Framework &#8211; part 2 </a></li>
<li><a href="/2010/07/22/zend_validate_db_recordexists-in-zend-framework-1-10/" rel="bookmark" title="Zend_Validate_Db_RecordExists in Zend Framework 1.10+">Zend_Validate_Db_RecordExists in Zend Framework 1.10+ </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>Once I <a title="_redirect with Zend Framework" href="/2010/04/21/setting-a-zend-framework-_redirect-referer/" target="_blank">wrote</a> about redirecting with Zend Framework, but what I missed back than was a common mistake. Although the code from my post is working, to be completely correct after redirecting I&#8217;d to add an exit() statement.</p>
<p>This is important because the header is changed and if something goes after the redirect there will be some problems. Finally the correct snippet is:</p>
<pre lang="php">
public function() {
	$this->_redirect('some_url');
	exit();	
}
</pre>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2009/11/27/redirecting-with-zend-framework/" rel="bookmark" title="Redirecting with Zend Framework">Redirecting with Zend Framework </a></li>
<li><a href="/2010/05/25/download-files-with-zend-framework/" rel="bookmark" title="Download Files with Zend Framework">Download Files with Zend Framework </a></li>
<li><a href="/2009/12/20/redirecting-with-zend-framework-part-2/" rel="bookmark" title="Redirecting with Zend Framework &#8211; part 2">Redirecting with Zend Framework &#8211; part 2 </a></li>
<li><a href="/2010/07/22/zend_validate_db_recordexists-in-zend-framework-1-10/" rel="bookmark" title="Zend_Validate_Db_RecordExists in Zend Framework 1.10+">Zend_Validate_Db_RecordExists in Zend Framework 1.10+ </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/06/21/redirect-with-zend-framework/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Setting a Zend Framework _redirect Referer</title>
		<link>/2010/04/21/setting-a-zend-framework-_redirect-referer/</link>
		<comments>/2010/04/21/setting-a-zend-framework-_redirect-referer/#comments</comments>
		<pubDate>Wed, 21 Apr 2010 12:18:57 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[zend framework]]></category>
		<category><![CDATA[controller]]></category>
		<category><![CDATA[HTTP referrer]]></category>
		<category><![CDATA[Hypertext]]></category>
		<category><![CDATA[Parameter]]></category>
		<category><![CDATA[URI scheme]]></category>
		<category><![CDATA[URL]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[World Wide Web]]></category>

		<guid isPermaLink="false">/?p=1466</guid>
		<description><![CDATA[Seems to be impossible, just because the only parameters you can set are far less than setting a referrer. Thus you&#8217;ve to rely on your browser capabilities. However the most reliable way is to redirect with referrer in mind. Something like _GET parameters. $this-&#62;_redirect('/url/return-to/1'); Once this parameter is processed by the controller/action you can return &#8230; <a href="/2010/04/21/setting-a-zend-framework-_redirect-referer/" class="more-link">Continue reading <span class="screen-reader-text">Setting a Zend Framework _redirect Referer</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2009/11/27/redirecting-with-zend-framework/" rel="bookmark" title="Redirecting with Zend Framework">Redirecting with Zend Framework </a></li>
<li><a href="/2009/04/21/zend-framework-disable-zend-layout/" rel="bookmark" title="Zend Framework &#8211; Disable Zend Layout">Zend Framework &#8211; Disable Zend Layout </a></li>
<li><a href="/2010/06/16/zend-examples-get-parameters-default-value/" rel="bookmark" title="Zend Examples: GET Parameters Default Value">Zend Examples: GET Parameters Default Value </a></li>
<li><a href="/2010/07/21/setting-up-global-cache-in-zend-framework/" rel="bookmark" title="Setting Up Global Cache in Zend Framework">Setting Up Global Cache in Zend Framework </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>Seems to be impossible, just because the only parameters you can set are far less than setting a referrer. Thus you&#8217;ve to rely on your browser capabilities. However the most reliable way is to redirect with referrer in mind. Something like _GET parameters.</p>
<pre lang="php" escaped="true">
$this-&gt;_redirect('/url/return-to/1');
</pre>
<p>Once this parameter is processed by the controller/action you can return to the referrer!</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2009/11/27/redirecting-with-zend-framework/" rel="bookmark" title="Redirecting with Zend Framework">Redirecting with Zend Framework </a></li>
<li><a href="/2009/04/21/zend-framework-disable-zend-layout/" rel="bookmark" title="Zend Framework &#8211; Disable Zend Layout">Zend Framework &#8211; Disable Zend Layout </a></li>
<li><a href="/2010/06/16/zend-examples-get-parameters-default-value/" rel="bookmark" title="Zend Examples: GET Parameters Default Value">Zend Examples: GET Parameters Default Value </a></li>
<li><a href="/2010/07/21/setting-up-global-cache-in-zend-framework/" rel="bookmark" title="Setting Up Global Cache in Zend Framework">Setting Up Global Cache in Zend Framework </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/04/21/setting-a-zend-framework-_redirect-referer/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Make your own link shortener</title>
		<link>/2010/01/28/make-your-own-link-shortener/</link>
		<comments>/2010/01/28/make-your-own-link-shortener/#respond</comments>
		<pubDate>Thu, 28 Jan 2010 08:09:44 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[caching]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Hash table]]></category>
		<category><![CDATA[Twitter Inc]]></category>
		<category><![CDATA[URL]]></category>
		<category><![CDATA[URL shortening]]></category>

		<guid isPermaLink="false">/?p=968</guid>
		<description><![CDATA[Why you should do that? First of all what’s a link shortener? Such online software exists and it’s widely used by the customers. Sites like bit.ly became extremely popular because of the growth of web apps like Facebook and especially Twitter. The simple goal that they achieve is to convert a long website uri into &#8230; <a href="/2010/01/28/make-your-own-link-shortener/" class="more-link">Continue reading <span class="screen-reader-text">Make your own link shortener</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/01/26/prevent-link-default-action-when-mousedown-and-mouseup-fires/" rel="bookmark" title="Prevent link default action when mousedown and mouseup fires!">Prevent link default action when mousedown and mouseup fires! </a></li>
<li><a href="/2010/06/04/one-form-multiple-db-records/" rel="bookmark" title="One Form &#8211; Multiple DB Records">One Form &#8211; Multiple DB Records </a></li>
<li><a href="/2010/03/09/what-make-javascript-closures-work/" rel="bookmark" title="What make JavaScript closures work?">What make JavaScript closures work? </a></li>
<li><a href="/2010/11/12/how-to-make-mp4-progressive-with-qt-faststart/" rel="bookmark" title="How to Make MP4 Progressive with qt-faststart">How to Make MP4 Progressive with qt-faststart </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>Why you should do that?</h2>
<p>First of all what’s a link shortener? Such online software exists and it’s widely used by the customers. Sites like bit.ly became extremely popular because of the growth of web apps like Facebook and especially Twitter. The simple goal that they achieve is to convert a long website uri into a short unique one. Beside that they give more information about who clicked that link and some useful stats along with that.</p>
<p>The question is why to make your own link shortener? One of the main reasons why is to paste links containing in plaintext your domain. In the case of <strong>http://stoimen.com/</strong> instead of using <strong>http://bit.ly/xxxxx</strong> it will be great if the link was something like <strong>http://stoimen.com/xxxx</strong> than pasting it into Twitter or wherever I get the primary impression of my domain.</p>
<h2>How to &#8230;</h2>
<p>It should be no mystery how to make your own. In fact you’ll need only one more table into the database, as this is the most common way to achieve it. Of course you can do that with no database using the file system to store the hash table in whatever format you’d like.</p>
<p>In the case of the DB solution you can simply make a table with three columns containing the unique id of the row, the short and the full link. Thus requesting some short link the db will return the “real” full uri. You can simply drop the short column if you’d like more efficient solution. Thus the unique identifier may become short link. That may be really fast if you’ve an index on the full link column.</p>
<p><strong>See the example below:</strong></p>
<blockquote>
<pre>id | short_link | full_link
1  | qwrt 	| /blog/2010/01/27/theory-of-caching-zend_cache-zend-optimizer</pre>
</blockquote>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/01/26/prevent-link-default-action-when-mousedown-and-mouseup-fires/" rel="bookmark" title="Prevent link default action when mousedown and mouseup fires!">Prevent link default action when mousedown and mouseup fires! </a></li>
<li><a href="/2010/06/04/one-form-multiple-db-records/" rel="bookmark" title="One Form &#8211; Multiple DB Records">One Form &#8211; Multiple DB Records </a></li>
<li><a href="/2010/03/09/what-make-javascript-closures-work/" rel="bookmark" title="What make JavaScript closures work?">What make JavaScript closures work? </a></li>
<li><a href="/2010/11/12/how-to-make-mp4-progressive-with-qt-faststart/" rel="bookmark" title="How to Make MP4 Progressive with qt-faststart">How to Make MP4 Progressive with qt-faststart </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/01/28/make-your-own-link-shortener/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
