<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" version="2.0">

<channel>
	<title>Enghiong</title>
	
	<link>http://www.enghiong.com</link>
	<description />
	<lastBuildDate>Mon, 16 Apr 2012 15:42: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>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/enghiong" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="enghiong" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">enghiong</feedburner:emailServiceId><feedburner:feedburnerHostname xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">http://feedburner.google.com</feedburner:feedburnerHostname><item>
		<title>MySQL Select Last n Records Without Changing The Order</title>
		<link>http://www.enghiong.com/mysql-select-last-n-records-without-changing-the-order.html</link>
		<comments>http://www.enghiong.com/mysql-select-last-n-records-without-changing-the-order.html#comments</comments>
		<pubDate>Mon, 16 Apr 2012 15:42:41 +0000</pubDate>
		<dc:creator>Administrator</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[last records of mysql table]]></category>
		<category><![CDATA[mysql last ordered records]]></category>
		<category><![CDATA[mysql select last rows]]></category>
		<category><![CDATA[mysql select n last records]]></category>
		<category><![CDATA[reorder mysql query result]]></category>
		<category><![CDATA[sorting mysql query result]]></category>
		<category><![CDATA[sorting mysql records]]></category>

		<guid isPermaLink="false">http://www.enghiong.com/?p=329</guid>
		<description><![CDATA[Let&#8217;s say I am going to select the last 10 records of a table. The main consideration would be using the query:
SELECT recordId
FROM myTable
ORDER BY recordId DESC
LIMIT 10
The above query would select the last 10 records but they would not be returned in the order they were inserted into the table.
There is another way to [...]]]></description>
			<content:encoded><![CDATA[<p>Let&#8217;s say I am going to select the last 10 records of a table. The main consideration would be using the query:</p>
<blockquote><p>SELECT recordId<br />
FROM myTable<br />
ORDER BY recordId DESC<br />
LIMIT 10</p></blockquote>
<p>The above query would select <a title="the last record" href="http://www.enghiong.com/get-the-last-record-from-a-table.html" target="_blank">the last</a> 10 records but they would not be returned in the order they were inserted into the table.<span id="more-329"></span></p>
<p>There is another way to do the query where first you select the count:</p>
<blockquote><p>SELECT COUNT(recordId) AS recordCount<br />
FROM myTable</p></blockquote>
<p>Let&#8217;s say it returns 50 records. Then we can subtract 10 and use the LIMIT keyword.</p>
<blockquote><p>SELECT recordId<br />
FROM myTable<br />
LIMIT 40, 10</p></blockquote>
<p>So that would give us the last 10 records, but 2 queries are needed. Can we do it with one query?</p>
<blockquote><p>SELECT recordId<br />
FROM myTable<br />
WHERE recordId<br />
IN (<br />
SELECT recordId<br />
FROM myTable<br />
ORDER BY recordId DESC<br />
LIMIT 10<br />
)<br />
ORDER BY recordId ASC</p></blockquote>
<p>The sub query finds the last 10 records and the main query compares against it while still keeping the order in tact. But this still looks complicated, and here is what I come up with:</p>
<blockquote><p>(SELECT recordId FROM myTable ORDER BY recordId DESC LIMIT 10) ORDER BY recordId ASC</p></blockquote>
<p>This should work well.</p>
<img src="http://www.enghiong.com/?ak_action=api_record_view&id=329&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.enghiong.com/mysql-select-last-n-records-without-changing-the-order.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to implement jQuery facebox plugin</title>
		<link>http://www.enghiong.com/how-to-implement-jquery-facebox-plugin.html</link>
		<comments>http://www.enghiong.com/how-to-implement-jquery-facebox-plugin.html#comments</comments>
		<pubDate>Thu, 02 Feb 2012 08:17:59 +0000</pubDate>
		<dc:creator>Administrator</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[facebook style lightbox]]></category>
		<category><![CDATA[facebox example]]></category>
		<category><![CDATA[facebox how to]]></category>
		<category><![CDATA[facebox plugin]]></category>
		<category><![CDATA[implementing facebox]]></category>
		<category><![CDATA[JQuery Example]]></category>
		<category><![CDATA[jQuery facebox]]></category>
		<category><![CDATA[jQuery lightbox]]></category>
		<category><![CDATA[jQuery plugin]]></category>

		<guid isPermaLink="false">http://www.enghiong.com/?p=324</guid>
		<description><![CDATA[
Facebox is a Facebook-style lightbox which can display any content loaded inside it such as images, divs, or entire remote pages.  It&#8217;s built based on JQuery.
In implementing facebox, the first thing you will have to do is, of course, to download facebox. It can be downloaded here.
Then extract the zip file and find &#8220;facebox.js&#8221;,&#8221;facebox.css&#8221;. Include [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.enghiong.com/wp-content/uploads/2012/02/Facebox-jQuery-Facebook-style-lightbox.jpg"><img class="size-full wp-image-325 alignnone" title="Facebox jQuery Facebook style lightbox" src="http://www.enghiong.com/wp-content/uploads/2012/02/Facebox-jQuery-Facebook-style-lightbox.jpg" alt="" width="417" height="247" /></a></p>
<p>Facebox is a Facebook-style lightbox which can display any content loaded inside it such as images, divs, or entire remote pages.  It&#8217;s built based on JQuery.<span id="more-324"></span></p>
<p>In implementing facebox, the first thing you will have to do is, of course, to download facebox. It can be downloaded <a title="Download facebox" href="https://github.com/defunkt/facebox/zipball/v1.3" target="_blank">here</a>.</p>
<p>Then extract the zip file and find &#8220;facebox.js&#8221;,&#8221;facebox.css&#8221;. Include the files in your code (please pay attention to the path of the files).</p>
<blockquote><p>&lt;script type=&#8221;text/javascript&#8221; src=&#8221;jQuery.js&#8221;&gt;&lt;/script&gt;<br />
&lt;script type=&#8221;text/javascript&#8221; src=&#8221;facebox.js&#8221;&gt;&lt;/script&gt;<br />
/** Additional Style **/<br />
&lt;link href=&#8221;facebox.css&#8221; rel=&#8221;stylesheet&#8221; type=&#8221;text/css&#8221;/&gt;</p></blockquote>
<p>if you don&#8217;t have &#8220;jQuery.js&#8221; you can use this code instead:</p>
<blockquote><p>&lt;script type=&#8221;text/javascript&#8221; src=&#8221;http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js&#8221; &gt;&lt;/script&gt;</p></blockquote>
<p>Next.. just call the javascript function that calls for facebox() method. For instance:</p>
<blockquote><p>&lt;script type=&#8221;text/javascript&#8221;&gt;<br />
function showFacebox(){<br />
jQuery.facebox(&#8220;&lt;p&gt;Hello World!&lt;/p&gt;&#8221;);<br />
}<br />
function ajaxFacebox(){<br />
jQuery.facebox(function() {<br />
var data = {};<br />
jQuery.post(&#8216;test.html&#8217;, data, function(response) {<br />
jQuery.facebox(response);<br />
})<br />
})<br />
}&lt;/script&gt;</p>
<p>&lt;p&gt;&lt;a href=&#8221;javascript:showFacebox()&#8221;&gt;Show Facebox&lt;/a&gt;&lt;/p&gt;<br />
&lt;p&gt;&lt;a href=&#8221;javascript:ajaxFacebox()&#8221;&gt;Show Facebox using ajax&lt;/a&gt;&lt;/p&gt;</p></blockquote>
<p>Facebox can also be called from an anchor text link that has a specific attribute such as the &#8216;rel&#8217; attribute.</p>
<blockquote><p>jQuery(document).ready(function($) {<br />
$(&#8220;a[rel*=anything]&#8220;).facebox();<br />
});</p></blockquote>
<p>The above code specifies that any link that has the &#8216;rel&#8217; attribute set to &#8216;anything&#8217; will have the content of its href attribute displayed inside the facebox.</p>
<p>Tips:<br />
How to change &#8216;close image&#8217; and &#8216;loading image&#8217;?<br />
Load the following code before jQuery.facebox() is called.</p>
<blockquote><p>$(document).bind(&#8216;init.facebox&#8217;, function() {<br />
$.facebox.settings.closeImage = &#8216;closelabel.png&#8217;;<br />
$.facebox.settings.loadingImage = &#8216;loading.gif&#8217;;<br />
})</p></blockquote>
<p>How to disable the background page?<br />
Well, you will have to edit facebox.js. Locate the function showOverlay(). Remark the line &#8220;.click(function() { $(document).trigger(&#8216;close.facebox&#8217;) })&#8221; as shown below:</p>
<blockquote><p>function showOverlay() {<br />
if (skipOverlay()) return</p>
<p>if ($(&#8216;#facebox_overlay&#8217;).length == 0)<br />
$(&#8220;body&#8221;).append(&#8216;&lt;div id=&#8221;facebox_overlay&#8221;&gt;&lt;/div&gt;&#8217;)</p>
<p>$(&#8216;#facebox_overlay&#8217;).hide().addClass(&#8220;facebox_overlayBG&#8221;)<br />
.css(&#8216;opacity&#8217;, $.facebox.settings.opacity)<br />
//.click(function() { $(document).trigger(&#8216;close.facebox&#8217;) })<br />
.fadeIn(200)<br />
return false<br />
}</p></blockquote>
<p>The complete example code for implementing jQuery facebox plugin can be downloaded <a title="Download facebox.zip" href="http://www.enghiong.com/download/facebox.zip">here</a>.</p>
<img src="http://www.enghiong.com/?ak_action=api_record_view&id=324&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.enghiong.com/how-to-implement-jquery-facebox-plugin.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PEAR Install Spreadsheet_Excel_Writer</title>
		<link>http://www.enghiong.com/pear-install-spreadsheet_excel_writer.html</link>
		<comments>http://www.enghiong.com/pear-install-spreadsheet_excel_writer.html#comments</comments>
		<pubDate>Fri, 02 Sep 2011 05:41:12 +0000</pubDate>
		<dc:creator>Administrator</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[failed install pear]]></category>
		<category><![CDATA[install pear preferred state stable]]></category>
		<category><![CDATA[PEAR install dependency]]></category>
		<category><![CDATA[pear installation error]]></category>
		<category><![CDATA[pear invalid or missing package file]]></category>
		<category><![CDATA[pear OLE]]></category>
		<category><![CDATA[Spreadsheet Excel Writer]]></category>

		<guid isPermaLink="false">http://www.enghiong.com/?p=319</guid>
		<description><![CDATA[When you attempt to install the Spreadsheet_Excel_Writer and get this error:
Failed to download pear/Spreadsheet_Excel_Writer within preferred state “stable”, latest release is version 0.9.1, stability “beta”, use “channel://pear.php.net/Spreadsheet_Excel_Writer-0.9.1? to install
Cannot initialize ‘channel://pear.php.net/Spreadsheet_Excel_Writer’, invalid or missing package file
Package “channel://pear.php.net/Spreadsheet_Excel_Writer” is not valid
install failed
do the following commands:
pear config-set preferred_state beta
pear install —onlyreqdeps Spreadsheet_Excel_Writer
Include the onlyreqdeps switch so that [...]]]></description>
			<content:encoded><![CDATA[<p>When you attempt to install the Spreadsheet_Excel_Writer and get this error:</p>
<blockquote><p>Failed to download pear/Spreadsheet_Excel_Writer within preferred state “stable”, latest release is version 0.9.1, stability “beta”, use “channel://pear.php.net/Spreadsheet_Excel_Writer-0.9.1? to install<br />
Cannot initialize ‘channel://pear.php.net/Spreadsheet_Excel_Writer’, invalid or missing package file<br />
Package “channel://pear.php.net/Spreadsheet_Excel_Writer” is not valid<br />
install failed</p></blockquote>
<p>do the following commands:</p>
<blockquote><p>pear config-set preferred_state beta<br />
pear install —onlyreqdeps Spreadsheet_Excel_Writer</p></blockquote>
<p>Include the <em>onlyreqdeps</em> switch so that the dependency package PEAR OLE is installed</p>
<p>Hope that will help!</p>
<img src="http://www.enghiong.com/?ak_action=api_record_view&id=319&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.enghiong.com/pear-install-spreadsheet_excel_writer.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP code to display Alexa rank</title>
		<link>http://www.enghiong.com/php-code-to-display-alexa-rank.html</link>
		<comments>http://www.enghiong.com/php-code-to-display-alexa-rank.html#comments</comments>
		<pubDate>Fri, 02 Sep 2011 05:35:04 +0000</pubDate>
		<dc:creator>Administrator</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[alexa rank]]></category>
		<category><![CDATA[alexarank code]]></category>
		<category><![CDATA[display website rank]]></category>
		<category><![CDATA[php code for alexarank]]></category>
		<category><![CDATA[script for alexa rank]]></category>
		<category><![CDATA[show page rank]]></category>
		<category><![CDATA[traffic rank]]></category>
		<category><![CDATA[website ranking]]></category>
		<category><![CDATA[website traffic]]></category>

		<guid isPermaLink="false">http://www.enghiong.com/?p=317</guid>
		<description><![CDATA[Alexa is a company owned by Amazon.com that measures web traffic on almost every website on the internet through their toolbar plugin. The Alexa Ranking is a ranking that is based on the traffic to a website. This ranking becomes an important thing in leveraging your website as a sell point to advertisers, sponsors, buyers, [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.alexa.com/">Alexa</a> is a company owned by <a href="http://www.amazon.com/">Amazon.com</a> that measures web traffic on almost every website on the internet through their toolbar plugin. The Alexa Ranking is a ranking that is based on the traffic to a website. This ranking becomes an important thing in leveraging your website as a sell point to advertisers, sponsors, buyers, readers and whoever else wants a piece of your material. Therefore for some website owners it’s important to put alexa rank in their page.</p>
<p>If you want to put alexa rank in your page, here is the code:</p>
<blockquote><p>&lt;?php</p>
<p>Class Alexa {</p>
<p>function getAlexaRank($domain)<br />
{<br />
$remote_url = ‘http://data.alexa.com/data?cli=10&amp;dat=snbamz&amp;url=’ . trim($domain);<br />
$xml = simplexml_load_file($remote_url);<br />
if(isset($xml-&gt;SD[1]-&gt;POPULARITY['TEXT'])){<br />
return number_format($xml-&gt;SD[1]-&gt;POPULARITY['TEXT']);<br />
} else {<br />
return 0;<br />
}<br />
}<br />
}<br />
?&gt;</p></blockquote>
<p>and</p>
<blockquote><p>$alexa = new Alexa;<br />
$alexarank = $alexa-&gt;getAlexaRank($domain);<br />
echo “Alexa Rank: ” . $alexarank;</p></blockquote>
<p>where $domain is your domain name.</p>
<p>ps: I got this script while googling, unfortunately I forgot the source.</p>
<img src="http://www.enghiong.com/?ak_action=api_record_view&id=317&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.enghiong.com/php-code-to-display-alexa-rank.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Configurations for Uploading File</title>
		<link>http://www.enghiong.com/php-configurations-for-uploading-file.html</link>
		<comments>http://www.enghiong.com/php-configurations-for-uploading-file.html#comments</comments>
		<pubDate>Fri, 02 Sep 2011 05:25:05 +0000</pubDate>
		<dc:creator>Administrator</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[php configurations]]></category>
		<category><![CDATA[php how to upload file]]></category>
		<category><![CDATA[php uploading files]]></category>
		<category><![CDATA[tips for uploading file]]></category>
		<category><![CDATA[trouble in uploading files]]></category>
		<category><![CDATA[upload file to server]]></category>
		<category><![CDATA[upload max filesize]]></category>

		<guid isPermaLink="false">http://www.enghiong.com/?p=314</guid>
		<description><![CDATA[The following are php configurations that must be considered when writing php program for uploading file to server:

allow_url_fopen – should be on
file_uploads – should be on
upload_max_file_size – is the sum of the sizes of all the files that you are uploading. This should be larger than the files you are trying to upload.
post_max_size – should [...]]]></description>
			<content:encoded><![CDATA[<p>The following are php configurations that must be considered when writing php program for uploading file to server:</p>
<ul>
<li>allow_url_fopen – should be on</li>
<li>file_uploads – should be on</li>
<li>upload_max_file_size – is the sum of the sizes of all the files that you are uploading. This should be larger than the files you are trying to upload.</li>
<li>post_max_size – should be larger than the value that you set for upload_max_file_size.</li>
<li>memory_limit – this directive has any effect only if you have used the –enable-memory-limit option at configuration time.</li>
<li>upload_tmp_dir – should be a valid directory and have correct permissions for the server to write to.</li>
<li>max_execution_time – should provide sufficient time.</li>
</ul>
<p>Files are usually posted to the server in a format known as ‘multipart/form-data’.</p>
<blockquote><p>&lt;form method=”post” enctype=”multipart/form-data”&gt;</p></blockquote>
<p>Tips: if you are encountering file uploading trouble, first try uploading a small text file.</p>
<img src="http://www.enghiong.com/?ak_action=api_record_view&id=314&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.enghiong.com/php-configurations-for-uploading-file.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>wp_insert_post could not insert post into the database</title>
		<link>http://www.enghiong.com/wp_insert_post-could-not-insert-post-into-the-database.html</link>
		<comments>http://www.enghiong.com/wp_insert_post-could-not-insert-post-into-the-database.html#comments</comments>
		<pubDate>Fri, 02 Sep 2011 05:16:05 +0000</pubDate>
		<dc:creator>Administrator</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[high ascii character]]></category>
		<category><![CDATA[mysql character set]]></category>
		<category><![CDATA[mysql data too long]]></category>
		<category><![CDATA[mysql set names]]></category>
		<category><![CDATA[preg_replace]]></category>
		<category><![CDATA[utf8_encode]]></category>
		<category><![CDATA[wp_insert_post]]></category>

		<guid isPermaLink="false">http://www.enghiong.com/?p=310</guid>
		<description><![CDATA[Today I experience hard time while writing wordpress plugin. The problem comes when I cannot insert post using wordpress function wp_insert_post. It failed when inserting the string “Each show lasts ’approximately’ ½ hour”. But to my surprise, I can write the string in wordpress editor and publish the post successfully. Nothing weird happens.
The error message [...]]]></description>
			<content:encoded><![CDATA[<p>Today I experience hard time while writing wordpress plugin. The problem comes when I cannot insert post using wordpress function <a title="wp_insert_post function" href="http://codex.wordpress.org/Function_Reference/wp_insert_post" target="_blank">wp_insert_post</a>. It failed when inserting the string “Each show lasts ’approximately’ ½ hour”. But to my surprise, I can write the string in wordpress editor and publish the post successfully. Nothing weird happens.</p>
<p>The error message generated from wp_insert_post function is “Could not insert post into the database”. And when I work further to the sql code the error is “Data too long for column ‘post_content’ at row 1 …”. That makes me more confuse.<span id="more-310"></span></p>
<p>While googling for “Data too long for column ‘post_content’ at row 1?, I see in some forums people are talking about the character set that causes the error.</p>
<p>Well.. Thanks Gods, I get the idea! Look at the string I am trying to insert to the post, it contains the ‘high-ascii’ character ’ (chr(146)) and ½ (chr(189)). I get this string from reading a textfile which is encoded in latin1 character set. All my mysql tables are in utf8_general_ci. In order to be able to insert the string to mysql table, I have to encode the string first. I try php function <a title="php utf8_encode() function" href="http://php.net/manual/en/function.utf8-encode.php" target="_blank">utf8_encode()</a> but it is not enough. This utf8_encode function cannot encode the ’ (chr(146)) character and therefore I convert it to HTML entities using preg_replace. The code looks like this:</p>
<blockquote><p>$post_content = utf8_encode(preg_replace(‘/([\200-\277])/e’, “‘&amp;#’.(ord(‘\\1?)).’;&#8217;”,$post_content)); $post_data=compact(‘post_excerpt’,&#8217;post_content’,&#8217;post_title’,&#8217;post_date’,&#8217;post_date_gmt’,&#8217;post_author’,&#8217;post_category’, ‘post_status’, ‘tags_input’);</p>
<p>$post_ID = wp_insert_post($post_data, true);</p></blockquote>
<p>Everything is okay now. The string is inserted successfully without any garbage character. So if you want to insert string that contains ‘high-ascii’ character encoded in different character set to mysql table, don’t forget to encode it first or you will get “Data too long for column….” error.</p>
<p>Another option (this is done manually outside the wordpress function) :<br />
Run mysql_query(“SET NAMES latin1?,$connection) before the insert query. But this is not recommended. The inserted data is still in latin1. You’ll need to encode them while reading.</p>
<img src="http://www.enghiong.com/?ak_action=api_record_view&id=310&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.enghiong.com/wp_insert_post-could-not-insert-post-into-the-database.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP in_array() and array_search() functions</title>
		<link>http://www.enghiong.com/php-in_array-and-array_search-functions.html</link>
		<comments>http://www.enghiong.com/php-in_array-and-array_search-functions.html#comments</comments>
		<pubDate>Fri, 02 Sep 2011 05:06:24 +0000</pubDate>
		<dc:creator>Administrator</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[array functions]]></category>
		<category><![CDATA[array_search function]]></category>
		<category><![CDATA[find array]]></category>
		<category><![CDATA[in_array function]]></category>
		<category><![CDATA[search array]]></category>

		<guid isPermaLink="false">http://www.enghiong.com/?p=307</guid>
		<description><![CDATA[What’s the difference between in_array() and array_search() in php?
The in_array() function checks if a value exists in an array. It returns TRUE if a value is found in the array, FALSE otherwise.
While the array_search() function searches the array for a given value and returns the corresponding key if successful. If not successful it returns FALSE.
As [...]]]></description>
			<content:encoded><![CDATA[<p>What’s the difference between <a title="PHP function in_array()" href="http://php.net/manual/en/function.in-array.php" target="_blank">in_array()</a> and <a title="PHP function array_search()" href="http://www.php.net/manual/en/function.array-search.php" target="_blank">array_search()</a> in php?</p>
<p>The <em>in_array()</em> function checks if a value exists in an array. It returns <strong>TRUE</strong> if a value is found in the array, <strong>FALSE</strong> otherwise.</p>
<p>While the <em>array_search()</em> function searches the array for a given value and returns the corresponding key if successful. If not successful it returns <strong>FALSE</strong>.<span id="more-307"></span></p>
<p>As <em>in_array()</em> function does not return the array key, it’s often used in  array without keys (the keys seem to be not important) like this:<br />
<code>$os = array("Mac", "NT", "Irix", "Linux");<br />
$exist = in_array("Irix", $os); // return TRUE</code></p>
<p>The <em>array_search()</em> function is used in this form of array:<br />
<code>$array = array('first' =&gt; 1, 'second' =&gt; 4);<br />
$key = array_search('4', $array); // $key = 'second'</code></p>
<p>Got it?</p>
<img src="http://www.enghiong.com/?ak_action=api_record_view&id=307&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.enghiong.com/php-in_array-and-array_search-functions.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Storing array data to MySQL using PHP</title>
		<link>http://www.enghiong.com/storing-array-data-to-mysql-using-php.html</link>
		<comments>http://www.enghiong.com/storing-array-data-to-mysql-using-php.html#comments</comments>
		<pubDate>Sun, 23 Jan 2011 07:02:00 +0000</pubDate>
		<dc:creator>Administrator</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[mysql store array in one field]]></category>
		<category><![CDATA[mysql working with array data]]></category>
		<category><![CDATA[php serialize]]></category>
		<category><![CDATA[php unserialize]]></category>
		<category><![CDATA[php working with array]]></category>
		<category><![CDATA[saving array to mysql]]></category>
		<category><![CDATA[store array to mysql]]></category>

		<guid isPermaLink="false">http://www.enghiong.com/?p=303</guid>
		<description><![CDATA[Suppose you want to store the information in array to your database. So in your PHP script, you may try something like this:
$cars=array(&#8220;Volvo&#8221;,&#8221;BMW&#8221;,&#8221;Toyota&#8221;);
$query=&#8221;INSERT INTO tablename (cars)  VALUES(&#8216;$cars&#8217;);
If you run the script you&#8217;ll get &#8220;Array&#8221; as your value in the database.
In order to make it works you&#8217;ll need to use PHP&#8217;s serialize() function. This function takes [...]]]></description>
			<content:encoded><![CDATA[<p>Suppose you want to store the information in array to your database. So in your PHP script, you may try something like this:</p>
<blockquote><p>$cars=array(&#8220;Volvo&#8221;,&#8221;BMW&#8221;,&#8221;Toyota&#8221;);<br />
$query=&#8221;INSERT INTO tablename (cars)  VALUES(&#8216;$cars&#8217;);</p></blockquote>
<p>If you run the script you&#8217;ll get &#8220;Array&#8221; as your value in the database.<span id="more-303"></span></p>
<p>In order to make it works you&#8217;ll need to use <abbr title="Hypertext Pre-processor">PHP</abbr>&#8217;s <a href="http://php.net/manual/en/function.serialize.php" target="_blank"><code>serialize()</code></a> function. This function takes arrays (and other data types), and converts the contents into data that can be stored.</p>
<blockquote><p>$cars=serialize(array(&#8220;Volvo&#8221;,&#8221;BMW&#8221;,&#8221;Toyota&#8221;));<br />
$query=&#8221;INSERT INTO tablename (cars) VALUES(&#8216;$cars&#8217;)&#8221;;</p></blockquote>
<p>But after you run the script if you look at your database, you&#8217;ll see something like this:</p>
<blockquote><p>a:3:{i:0;s:5:&#8221;Volvo&#8221;;i:1;s:3:&#8221;BMW&#8221;;i:2;s:6:&#8221;Toyota&#8221;;}</p></blockquote>
<p>Don&#8217;t worry! To retrieve the array data from the database use  <a href="http://www.php.net/manual/en/function.unserialize.php" target="_blank"><code>unserialize()</code></a> function.  <code>unserialize()</code> takes serialized array data and converts it back to a usable array.</p>
<p>Then, you might do this:</p>
<blockquote><p>$query=&#8221;SELECT * FROM tablename&#8221;;<br />
$result=mysql_query($query);<br />
$row = mysql_fetch_object($result));<br />
$cars=unserialize($row-&gt;cars);</p></blockquote>
<p>There you get back your array.</p>
<img src="http://www.enghiong.com/?ak_action=api_record_view&id=303&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.enghiong.com/storing-array-data-to-mysql-using-php.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How To Write print_r Output To File</title>
		<link>http://www.enghiong.com/how-to-write-print_r-output-to-file.html</link>
		<comments>http://www.enghiong.com/how-to-write-print_r-output-to-file.html#comments</comments>
		<pubDate>Thu, 30 Dec 2010 15:01:38 +0000</pubDate>
		<dc:creator>Administrator</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[php array function]]></category>
		<category><![CDATA[php function print_r]]></category>
		<category><![CDATA[print array to file]]></category>
		<category><![CDATA[print_r function]]></category>
		<category><![CDATA[print_r output]]></category>
		<category><![CDATA[print_r to file]]></category>
		<category><![CDATA[write array to file]]></category>

		<guid isPermaLink="false">http://www.enghiong.com/?p=301</guid>
		<description><![CDATA[While working with PHP array, it&#8217;s quite often to know what data inside the array. For this purpose we can use print_r() function to display the data contained by the array to the screen. But what if we are working on a program that run behind the screen such as remote connection program, application that [...]]]></description>
			<content:encoded><![CDATA[<p>While working with PHP array, it&#8217;s quite often to know what data inside the array. For this purpose we can use print_r() function to display the data contained by the array to the screen. But what if we are working on a program that run behind the screen such as remote connection program, application that calls the <a title="curl" href="http://www.enghiong.com/call-to-undefined-function-curl_init.html" target="_blank">curl</a>, or wordpress plugin that does not use a web browser. We need to write the output to a file, a log file isn&#8217;t that&#8230;?</p>
<p>Here is the trick:</p>
<blockquote><p>ob_start(); //Start buffering<br />
print_r($the_array); //print the array to buffer<br />
$output = ob_get_contents(); //get the result from buffer<br />
ob_end_clean(); //close buffer</p>
<p>$h = fopen(&#8216;logfile.txt&#8217;, &#8216;w&#8217;); //open a file<br />
fwrite($h, $output); //write the output text<br />
fclose($h); //close file</p></blockquote>
<p>Then manually open the created <a title="How to write text file" href="http://www.enghiong.com/php-how-to-write-to-text-file.html" target="_blank">text file</a> to see what happens&#8230;</p>
<img src="http://www.enghiong.com/?ak_action=api_record_view&id=301&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.enghiong.com/how-to-write-print_r-output-to-file.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Redirect Page</title>
		<link>http://www.enghiong.com/php-redirect-page.html</link>
		<comments>http://www.enghiong.com/php-redirect-page.html#comments</comments>
		<pubDate>Tue, 23 Nov 2010 08:43:59 +0000</pubDate>
		<dc:creator>Administrator</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[page redirection]]></category>
		<category><![CDATA[php modify header]]></category>
		<category><![CDATA[php page buffering]]></category>
		<category><![CDATA[php redirect function]]></category>
		<category><![CDATA[php redirect page]]></category>

		<guid isPermaLink="false">http://www.enghiong.com/?p=297</guid>
		<description><![CDATA[For one or more reason it can be useful to automatically redirect visitors to another web page especially when the page they are trying to access is no longer exists. Using this method, they can be seamlessly transfered to the new page without having to click a link to continue.
To make a page redirection in [...]]]></description>
			<content:encoded><![CDATA[<p>For one or more reason it can be useful to automatically redirect visitors to another web page especially when the page they are trying to access is no longer exists. Using this method, they can be seamlessly transfered to the new page without having to click a link to continue.</p>
<p>To make a <a title="Redirecting page using javascript" href="http://www.enghiong.com/redirecting-page-using-javascript.html" target="_blank">page redirection</a> in php you can use the header() function and it is quite an easy task.</p>
<blockquote><p>header( &#8216;Location: http://www.yourdomain.com/new_page.html&#8217; ) ;</p></blockquote>
<p>This function must be called before any actual output is sent unless you will get the following error:</p>
<blockquote><p>Warning: Cannot modify header information &#8211; headers already sent by</p></blockquote>
<p>Or you can use ob_start() and ob_flush() function to avoid this problem by buffering the output.</p>
<blockquote><p>ob_start();<br />
echo &#8220;Test&#8221;;<br />
header( &#8216;Location: http://www.yourdomain.com/new_page.html&#8217; ) ;<br />
ob_flush();</p></blockquote>
<p>Note that the code after the header function will still be executed, so to save resources you should call a die() function after the redirection.</p>
<img src="http://www.enghiong.com/?ak_action=api_record_view&id=297&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.enghiong.com/php-redirect-page.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss><!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Database Caching 1/7 queries in 0.011 seconds using disk: basic
Object Caching 659/719 objects using disk: basic

Served from: www.enghiong.com @ 2012-05-22 14:05:32 -->

