<?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>encode() &#8211; stoimen&#039;s web log</title>
	<atom:link href="/tag/encode/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>Returning JSON in a Zend Controller&#8217;s Action</title>
		<link>/2010/08/13/returning-json-in-a-zend-controllers-action/</link>
		<comments>/2010/08/13/returning-json-in-a-zend-controllers-action/#comments</comments>
		<pubDate>Fri, 13 Aug 2010 13:14:26 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[zend framework]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[clear solution]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[encode()]]></category>
		<category><![CDATA[JavaScript programming language]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[JSON-RPC]]></category>
		<category><![CDATA[Markup languages]]></category>
		<category><![CDATA[Software engineering]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[zend_json]]></category>

		<guid isPermaLink="false">/?p=1905</guid>
		<description><![CDATA[There are three basic ways that you can achieve that. First of all what&#8217;s the task? You&#8217;ve an array, either from a database result or whatever, and you encode it JSON with Zend_Json::encode($array) // IndexController.php class IndexController extends Zend_Controller_Action { public function indexAction() { $data = array(...); $this->view->data = Zend_Json::encode($data); } } The result in &#8230; <a href="/2010/08/13/returning-json-in-a-zend-controllers-action/" class="more-link">Continue reading <span class="screen-reader-text">Returning JSON in a Zend Controller&#8217;s Action</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/08/19/returning-json-in-a-zend-controller%e2%80%99s-action-part-2/" rel="bookmark" title="Returning JSON in a Zend Controller’s Action &#8211; Part 2">Returning JSON in a Zend Controller’s Action &#8211; Part 2 </a></li>
<li><a href="/2010/06/10/json-and-zend-framework-zend_json/" rel="bookmark" title="JSON and Zend Framework? &#8211; Zend_Json">JSON and Zend Framework? &#8211; Zend_Json </a></li>
<li><a href="/2010/06/07/bind-zend-action-with-non-default-view/" rel="bookmark" title="Bind Zend Action with Non-Default View">Bind Zend Action with Non-Default View </a></li>
<li><a href="/2010/06/24/zend-framework-inject-javascript-code-in-a-actionview/" rel="bookmark" title="Zend Framework: Inject JavaScript Code in a Action/View">Zend Framework: Inject JavaScript Code in a Action/View </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>There are three basic ways that you can achieve that. First of all what&#8217;s the task? You&#8217;ve an array, either from a database result or whatever, and you encode it JSON with Zend_Json::encode($array)</p>
<pre lang="php">
// IndexController.php
class IndexController extends Zend_Controller_Action
{
	public function indexAction()
	{
		$data = array(...);
		
		$this->view->data = Zend_Json::encode($data);	
	}	
}
</pre>
<p>The result in general is a specially formatted string. So you can simply set it up to a view member variable and pass it to the view.</p>
<pre lang="php">
// index/index.phtml
echo $this->data
</pre>
<p>In that case you&#8217;ve a .phtml file to maintain, so lets just return the string and &#8220;setNoRender&#8221; the view in our second try.</p>
<pre lang="php">
// IndexController.php
class IndexController extends Zend_Controller_Action
{
	public function indexAction()
	{
		$data = array(...);
		
		echo Zend_Json::encode($data);	
		
		$this->_helper->viewRenderer->setNoRender(true);
	}	
}
</pre>
<p>Actually this is pretty much the most clear solution, but actually you can output the JSON string and simply exit() as it&#8217;s shown in our third example.</p>
<pre lang="php">
// IndexController.php
class IndexController extends Zend_Controller_Action
{
	public function indexAction()
	{
		$data = array(...);
		
		echo Zend_Json::encode($data);	
		
		exit();
	}	
}
</pre>
<p>Which one is to be used is up to the developer&#8217;s choice, mine is the third one as it&#8217;s the minimal one.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/08/19/returning-json-in-a-zend-controller%e2%80%99s-action-part-2/" rel="bookmark" title="Returning JSON in a Zend Controller’s Action &#8211; Part 2">Returning JSON in a Zend Controller’s Action &#8211; Part 2 </a></li>
<li><a href="/2010/06/10/json-and-zend-framework-zend_json/" rel="bookmark" title="JSON and Zend Framework? &#8211; Zend_Json">JSON and Zend Framework? &#8211; Zend_Json </a></li>
<li><a href="/2010/06/07/bind-zend-action-with-non-default-view/" rel="bookmark" title="Bind Zend Action with Non-Default View">Bind Zend Action with Non-Default View </a></li>
<li><a href="/2010/06/24/zend-framework-inject-javascript-code-in-a-actionview/" rel="bookmark" title="Zend Framework: Inject JavaScript Code in a Action/View">Zend Framework: Inject JavaScript Code in a Action/View </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/08/13/returning-json-in-a-zend-controllers-action/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>JavaScript encode cyrillic symbols with encodeURIComponent</title>
		<link>/2009/05/25/javascript-encode-cyrillic-symbols-with-encodeuricomponent/</link>
		<comments>/2009/05/25/javascript-encode-cyrillic-symbols-with-encodeuricomponent/#respond</comments>
		<pubDate>Mon, 25 May 2009 13:46:22 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[cyrillic]]></category>
		<category><![CDATA[encode()]]></category>
		<category><![CDATA[encodeURIComponent()]]></category>

		<guid isPermaLink="false">/?p=585</guid>
		<description><![CDATA[JavaScript and Cyrillic Let&#8217;s assume we&#8217;ve a JavaScript file which rewrites the location.href, resulting in changes in the URI of the browser. Everything is OK till you work with Latin alphabet. The problem arises when you decide to put some Cyrillic symbols into the string. The encode() function With that function you can encode the &#8230; <a href="/2009/05/25/javascript-encode-cyrillic-symbols-with-encodeuricomponent/" class="more-link">Continue reading <span class="screen-reader-text">JavaScript encode cyrillic symbols with encodeURIComponent</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2009/03/05/flex-3-import-swf-symbols/" rel="bookmark" title="Flex 3 import swf symbols">Flex 3 import swf symbols </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="/2011/07/28/oop-javascript-accessing-public-methods-in-private-methods/" rel="bookmark" title="OOP JavaScript: Accessing Public Methods in Private Methods">OOP JavaScript: Accessing Public Methods in Private Methods </a></li>
<li><a href="/2010/01/31/speed-up-the-javascript-it-can-change-dramatically-the-user-experience/" rel="bookmark" title="Speed up the JavaScript. It can change dramatically the user experience.">Speed up the JavaScript. It can change dramatically the user experience. </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>JavaScript and Cyrillic</h2>
<p>Let&#8217;s assume we&#8217;ve a JavaScript file which rewrites the location.href, resulting in changes in the URI of the browser. Everything is OK till you work with Latin alphabet. The problem arises when you decide to put some Cyrillic symbols into the string.</p>
<h2>The encode() function</h2>
<p>With that function you can encode the URL if you have some entity symbols. It is not like but it should be something like encodeURI in PHP. The problem is that this function does not work correctly with Cyrillic symbols.</p>
<h2>Use encodeURIComponent</h2>
<p>There is another usefull function which does this. It&#8217;s called encodeURIComponent, and I strongly recomment its use.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2009/03/05/flex-3-import-swf-symbols/" rel="bookmark" title="Flex 3 import swf symbols">Flex 3 import swf symbols </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="/2011/07/28/oop-javascript-accessing-public-methods-in-private-methods/" rel="bookmark" title="OOP JavaScript: Accessing Public Methods in Private Methods">OOP JavaScript: Accessing Public Methods in Private Methods </a></li>
<li><a href="/2010/01/31/speed-up-the-javascript-it-can-change-dramatically-the-user-experience/" rel="bookmark" title="Speed up the JavaScript. It can change dramatically the user experience.">Speed up the JavaScript. It can change dramatically the user experience. </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2009/05/25/javascript-encode-cyrillic-symbols-with-encodeuricomponent/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
