<?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>Haiders WebSpace &#187; PHP</title>
	<atom:link href="http://blog.creativeitp.com/category/posts-and-articles/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.creativeitp.com</link>
	<description>Let&#039;s talk about IT</description>
	<lastBuildDate>Sat, 27 Feb 2010 13:15:05 +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>Detect ie (Internet Explorer)</title>
		<link>http://blog.creativeitp.com/posts-and-articles/php/detect-ie-internet-explorer/</link>
		<comments>http://blog.creativeitp.com/posts-and-articles/php/detect-ie-internet-explorer/#comments</comments>
		<pubDate>Sun, 23 Aug 2009 15:25:51 +0000</pubDate>
		<dc:creator>Haider al-Khateeb</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Internet Explorer]]></category>

		<guid isPermaLink="false">http://blog.creativeitp.com/?p=95</guid>
		<description><![CDATA[Here is a code to detect weather the visitor if your webpage is using ie or not: 1 2 3 4 5 6 7 8 if &#40;isset&#40;$_SERVER&#91;'HTTP_USER_AGENT'&#93;&#41; &#38;&#38; &#40;strpos&#40;$_SERVER&#91;'HTTP_USER_AGENT'&#93;, 'MSIE'&#41; !== false&#41;&#41; &#123; echo &#34;You are using ie&#34;; &#125; else &#123; echo &#34;You are not using ie&#34;; &#125; I am using this simple PHP code [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;">
<p style="text-align: justify;">Here is a code to detect weather the visitor if your webpage is using <i>ie</i> or not:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_USER_AGENT'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> 
    <span style="color: #009900;">&#40;</span><span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_USER_AGENT'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'MSIE'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!==</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> 
	<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;You are using ie&quot;</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: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;You are not using ie&quot;</span><span style="color: #339933;">;</span> 
	<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p style="text-align: justify;">
<p style="text-align: justify;">I am using this simple PHP code while developing HybridPass, a new authentication tool for web applications. My Javascript is only compatible with <i>ie</i> at the moment, so until I develop it more to support other browsers it is important to give my visitors the right feedback.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.creativeitp.com/posts-and-articles/php/detect-ie-internet-explorer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Display Generate random values (array_rand)</title>
		<link>http://blog.creativeitp.com/posts-and-articles/php/display-generate-random-values-array_rand/</link>
		<comments>http://blog.creativeitp.com/posts-and-articles/php/display-generate-random-values-array_rand/#comments</comments>
		<pubDate>Fri, 13 Mar 2009 15:30:42 +0000</pubDate>
		<dc:creator>Haider al-Khateeb</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.creativeitp.com/?p=98</guid>
		<description><![CDATA[array_rand can be used to select a list of values randomly. This helped me to code a server side script to display a random grid of pictures as part of a project. These pictures changes every time the page is requested or refreshed. Below is an example: 1 2 3 4 5 6 7 8 [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;">
<p style="text-align: justify;"><b>array_rand</b> can be used to select a list of values randomly. This helped me to code a server side script to display a random grid of pictures as part of a project. These pictures changes every time the page is requested or refreshed.</p>
<p><span id="more-98"></span><br />
Below is an example:</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
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #990000;">srand</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>float<span style="color: #009900;">&#41;</span> <span style="color: #990000;">microtime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">10000000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$input</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;lion.gif&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;cat.gif&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;dog.gif&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;bird.gif&quot;</span><span style="color: #339933;">,</span> 
<span style="color: #0000ff;">&quot;tiger.gif&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;eagle.gif&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$rand_keys</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_rand</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$input</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
&lt;table align=&quot;center&quot; cellspacing=&quot;15&quot;&gt;
&lt;tr&gt;
&lt;td  bgcolor=&quot;#f0f0f0&quot; align=&quot;middle&quot;&gt;
&lt;img src=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$input</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$rand_keys</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;
&lt;/td&gt;
&lt;td  bgcolor=&quot;#f0f0f0&quot; align=&quot;middle&quot;&gt;
&lt;img src=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$input</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$rand_keys</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td  bgcolor=&quot;#f0f0f0&quot; align=&quot;middle&quot;&gt;
&lt;img src=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$input</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$rand_keys</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;
&lt;/td&gt;
&lt;td  bgcolor=&quot;#f0f0f0&quot; align=&quot;middle&quot;&gt;
&lt;img src=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$input</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$rand_keys</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;
&lt;/tr&gt;
&lt;/table&gt;</pre></td></tr></table></div>

<p style="text-align: justify;">
]]></content:encoded>
			<wfw:commentRss>http://blog.creativeitp.com/posts-and-articles/php/display-generate-random-values-array_rand/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Retrieve data as UTF-8 from MySQL DB</title>
		<link>http://blog.creativeitp.com/posts-and-articles/phpbb/retrieve-data-as-utf-8-from-mysql-db/</link>
		<comments>http://blog.creativeitp.com/posts-and-articles/phpbb/retrieve-data-as-utf-8-from-mysql-db/#comments</comments>
		<pubDate>Mon, 02 Mar 2009 15:43:39 +0000</pubDate>
		<dc:creator>Haider al-Khateeb</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[phpBB]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://blog.creativeitp.com/?p=100</guid>
		<description><![CDATA[The image above is showing part of a small hack I coded for a phpBB board to show topics from selected sections. Those question marks were suppose to be Arabic letters, but after a recent update to phpBB the hack failed to use the board config file to connect so I had to set up [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">
<p style="text-align: center;">
<div id="attachment_102" class="wp-caption aligncenter" style="width: 478px"><img src="http://blog.creativeitp.com/wp-content/uploads/2010/01/charset-problem02.jpg" alt="" title="Charset Problem" width="468" height="58" class="size-full wp-image-102" /><p class="wp-caption-text">Charset Problem</p></div>
</p>
<p style="text-align: center;">
<p style="text-align: justify;">The image above is showing part of a small hack I coded for a phpBB board to show topics from selected sections. Those question marks were suppose to be Arabic letters, but after a recent update to phpBB the hack failed to use the board config file to connect so I had to set up my own direct connection to the DB.</p>
</p>
<p style="text-align: justify;">The connection was fine, but I got &#8220;?????&#8221; instead of something I can read in Arabic. After some tests I figured out, though the MySQL DB is using UTF-8 as a character set, which means it can handle the language efficiently, I had to set the character set to UTF-8 via PHP for every query using the following code:</p>
<p style="text-align: justify;">
<p style="text-align: justify;">

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SET CHARACTER SET utf8&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

</p>
<p style="text-align: justify;">
<p style="text-align: justify;">What is even better is setting the character set at once with a single line of code for the whole connection by using the following code:</p>
<p><span id="more-100"></span></p>
<p style="text-align: justify;">
<p style="text-align: justify;">

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SET CHARACTER SET 'utf8'&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$db</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

</p>
<p style="text-align: justify;">
<p style="text-align: justify;">This code should be used directly after the connection, as in the following example:</p>
<p style="text-align: justify;">
<p style="text-align: justify;">

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"> <span style="color: #000088;">$db</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'localhost'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'DB_USER'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'DB_PASSWORD'</span><span style="color: #009900;">&#41;</span> 
or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Could not connect&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">mysql_select_db</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'DB_NAME'</span><span style="color: #339933;">,</span><span style="color: #000088;">$db</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Could not connect&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
  <span style="color: #666666; font-style: italic;">// Set character set to UTF-8</span>
  <span style="color: #666666; font-style: italic;">//</span>
  <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SET CHARACTER SET 'utf8'&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$db</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

</p>
<p style="text-align: justify;">
<p style="text-align: justify;">Now I got my topics in readable Arabic once again!</p>
<p style="text-align: justify;">
<p style="text-align: center;">
<div id="attachment_101" class="wp-caption aligncenter" style="width: 476px"><img src="http://blog.creativeitp.com/wp-content/uploads/2010/01/charset-problem01.jpg" alt="" title="Charset Problem Solved" width="466" height="57" class="size-full wp-image-101" /><p class="wp-caption-text">Charset Problem Solved</p></div>
<p style="text-align: justify;">
]]></content:encoded>
			<wfw:commentRss>http://blog.creativeitp.com/posts-and-articles/phpbb/retrieve-data-as-utf-8-from-mysql-db/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
