<?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:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Rene's PHP Blog</title>
	
	<link>http://www.phpz.nl</link>
	<description>My PHP experiences</description>
	<pubDate>Tue, 05 May 2009 23:44:20 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
	<language>en</language>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/phpz" /><feedburner:info uri="phpz" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Fresh Start</title>
		<link>http://feedproxy.google.com/~r/phpz/~3/rbFxiKCoUoU/</link>
		<comments>http://www.phpz.nl/?p=79#comments</comments>
		<pubDate>Tue, 05 May 2009 23:44:20 +0000</pubDate>
		<dc:creator>Rene Pot</dc:creator>
		
		<category><![CDATA[general]]></category>

		<category><![CDATA[fresh start new domain blog rene pot renepot.com]]></category>

		<guid isPermaLink="false">http://www.phpz.nl/?p=79</guid>
		<description><![CDATA[Because of my increase in experience in more languages than just PHP, i decided to make a suitable blog for that matter.
Therefor I decided to move any future posts to a new domain. And this will be www.renepot.com
I hope to see you all there!
]]></description>
			<content:encoded><![CDATA[<p>Because of my increase in experience in more languages than just PHP, i decided to make a suitable blog for that matter.</p>
<p>Therefor I decided to move any future posts to a new domain. And this will be <a href="http://www.renepot.com" target="_blank">www.renepot.com</a></p>
<p>I hope to see you all there!</p>
<img src="http://feeds.feedburner.com/~r/phpz/~4/rbFxiKCoUoU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.phpz.nl/?feed=rss2&amp;p=79</wfw:commentRss>
		<feedburner:origLink>http://www.phpz.nl/?p=79</feedburner:origLink></item>
		<item>
		<title>PHP’s function Code Highlighting</title>
		<link>http://feedproxy.google.com/~r/phpz/~3/1s3KFd686QY/</link>
		<comments>http://www.phpz.nl/?p=74#comments</comments>
		<pubDate>Thu, 30 Apr 2009 09:49:29 +0000</pubDate>
		<dc:creator>Rene Pot</dc:creator>
		
		<category><![CDATA[Sugestions]]></category>

		<category><![CDATA[general]]></category>

		<category><![CDATA[code]]></category>

		<category><![CDATA[default]]></category>

		<category><![CDATA[function]]></category>

		<category><![CDATA[highlight]]></category>

		<category><![CDATA[highlighting]]></category>

		<category><![CDATA[php]]></category>

		<category><![CDATA[suggestion]]></category>

		<guid isPermaLink="false">http://www.phpz.nl/?p=74</guid>
		<description><![CDATA[PHP's function code highlighting is a very easy and simple way to display any php code on your website without having to write difficult functions.]]></description>
			<content:encoded><![CDATA[<p>Just recently i discovered something very usefull. It could be very helpfull in any website or forum regarding programming.</p>
<p>There is a function in PHP called Code Highlighting. This would result in a very easy way of displaying php code onto a website. Just let me give an example.</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #990000;">highlight_string</span><span style="color: #009900;">&#40;</span><span style="">'&lt;?php echo &quot;test&quot;; ?&gt;'</span><span style="color: #009900;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>This outputted this in the displayed HTML:</p>
<p>&lt;span style=&#8221;color: rgb(0, 0, 187);&#8221;&gt;&amp;lt;?php&amp;nbsp;&lt;/span&gt;&lt;span style=&#8221;color: rgb(0, 119, 0);&#8221;&gt;echo&amp;nbsp;&lt;/span&gt;&lt;span style=&#8221;color: rgb(221, 0, 0);&#8221;&gt;&#8221;test&#8221;&lt;/span&gt;&lt;span style=&#8221;color: rgb(0, 119, 0);&#8221;&gt;;&amp;nbsp;&lt;/span&gt;&lt;span style=&#8221;color: rgb(0, 0, 187);&#8221;&gt;?&amp;gt;&lt;/span&gt;<br />
&lt;/span&gt;</p>
<p>Which looks just like this:<br />
<span style="color: rgb(0, 0, 187);">&lt;?php&nbsp;</span><span style="color: rgb(0, 119, 0);">echo&nbsp;</span><span style="color: rgb(221, 0, 0);">&#8220;test&#8221;</span><span style="color: rgb(0, 119, 0);">;&nbsp;</span><span style="color: rgb(0, 0, 187);">?&gt;</span><br />
</span><br />
As you can see, this can be very helpful. </p>
<p>Of course you need to be careful with this function as soon as you use it in &#8220;public&#8221;. You need to make sure you escape every quotes in the string with addslashes. This will prevent anything from happening.<br />
Of course i can&#8217;t guarantee 100% protection. That&#8217;s pretty tricky. Good luck!<br />
PS: <a href="http://nl2.php.net/manual/en/function.highlight-file.php">http://nl2.php.net/manual/en/function.highlight-file.php</a></p>
<img src="http://feeds.feedburner.com/~r/phpz/~4/1s3KFd686QY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.phpz.nl/?feed=rss2&amp;p=74</wfw:commentRss>
		<feedburner:origLink>http://www.phpz.nl/?p=74</feedburner:origLink></item>
		<item>
		<title>PHP 5 Recipes: A Problem-Solution Approach</title>
		<link>http://feedproxy.google.com/~r/phpz/~3/UTLidkZfiLo/</link>
		<comments>http://www.phpz.nl/?p=72#comments</comments>
		<pubDate>Mon, 27 Apr 2009 12:29:44 +0000</pubDate>
		<dc:creator>Rene Pot</dc:creator>
		
		<category><![CDATA[Sugestions]]></category>

		<category><![CDATA[book]]></category>

		<category><![CDATA[php]]></category>

		<category><![CDATA[PHP 5 Recipes: A Problem-Solution Approach]]></category>

		<category><![CDATA[suggestion]]></category>

		<guid isPermaLink="false">http://www.phpz.nl/?p=72</guid>
		<description><![CDATA[A very good book: PHP 5 Recipes: A Problem-Solution Approach. Really helpfull for php programmers]]></description>
			<content:encoded><![CDATA[<p>Recently I bought this PHP book, and i must say, it&#8217;s a good one! There is more than just some examples. They show you how to fix a problem the best way! It is really worth buying.</p>
<p>Just want to recommend a good book!</p>
<p><a href="http://www.amazon.com/gp/product/1590595092?ie=UTF8&amp;tag=gafous0d-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=1590595092">PHP 5 Recipes: A Problem-Solution Approach</a></p>
<p><img src="https://images-na.ssl-images-amazon.com/images/I/41gkJEN0v1L._SL500_PIsitb-sticker-arrow-big,TopRight,35,-73_OU01_SL75_.jpg" border="0" alt="" width="73" height="96" /><br />
<a href="http://www.amazon.com/gp/product/1590595092?ie=UTF8&amp;tag=gafous0d-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=1590595092"></a><img style="border:none !important; margin:0px !important;" src="http://www.assoc-amazon.com/e/ir?t=gafous0d-20&amp;l=as2&amp;o=1&amp;a=1590595092" border="0" alt="" width="1" height="1" /></p>
<img src="http://feeds.feedburner.com/~r/phpz/~4/UTLidkZfiLo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.phpz.nl/?feed=rss2&amp;p=72</wfw:commentRss>
		<feedburner:origLink>http://www.phpz.nl/?p=72</feedburner:origLink></item>
		<item>
		<title>Mysql Full Text Search - Speed up those results</title>
		<link>http://feedproxy.google.com/~r/phpz/~3/Lne8uyHzw4g/</link>
		<comments>http://www.phpz.nl/?p=70#comments</comments>
		<pubDate>Fri, 24 Apr 2009 20:02:09 +0000</pubDate>
		<dc:creator>Rene Pot</dc:creator>
		
		<category><![CDATA[PHP Problems]]></category>

		<category><![CDATA[Sugestions]]></category>

		<category><![CDATA[general]]></category>

		<category><![CDATA[against]]></category>

		<category><![CDATA[database]]></category>

		<category><![CDATA[full]]></category>

		<category><![CDATA[full text search]]></category>

		<category><![CDATA[match]]></category>

		<category><![CDATA[mysql]]></category>

		<category><![CDATA[php]]></category>

		<category><![CDATA[query]]></category>

		<category><![CDATA[search]]></category>

		<category><![CDATA[speed]]></category>

		<category><![CDATA[table]]></category>

		<category><![CDATA[text]]></category>

		<guid isPermaLink="false">http://www.phpz.nl/?p=70</guid>
		<description><![CDATA[A very easy way of getting results from a mysql database in no-time using the full text search function of mysql.]]></description>
			<content:encoded><![CDATA[<p>I just ran into the problem of a very big database, and a very slow search function..</p>
<p>At first i was a little confused, but soon i came to the conclusion of building a Full Text Search function.</p>
<p>The first problem on building this i encountered was the database coalition. You have to have a <strong>MyISAM</strong> database. So, that&#8217;s what i did.</p>
<ul>
<li>Create a table:</li>
</ul>
<p>CREATE TABLE news (content TEXT, title VARCHAR(250), id INT(11) NOT NULL auto_increment, PRIMARY KEY(id);</p>
<ul>
<li>Add a fulltext index:</li>
</ul>
<p>ALTER TABLE articles ADD FULLTEXT(content, title);</p>
<p>This FULLTEXT index makes an index on both content and title, so you can&#8217;t search just one of them.</p>
<ul>
<li>Create a Query:</li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT title,content,id, MATCH(title,content) AGAINST ('my search') AS score FROM news WHERE MATCH(title,content) AGAINST ('my search')&quot;</span>;</pre></div></div>

<p>Let me explain:</p>
<p><strong><em>SELECT MATCH(title,content) AGAINST (&#8217;my search&#8217;)</em></strong> means you select the result of a MATCH. The result is a score. The higher the number, the better the result.</p>
<p><em> <strong>AGAINST (&#8217;my search&#8217;) </strong></em>searches in the selected fields in the MATCH (title,content) in my example. The search can be multiple words. The search searches for all words individually. You can also add a minus (-) and a plus (+) to a word, in order to change the priority. A minus tries searching a row without the word, a plus makes a word more imporant.</p>
<p>The reason the MATCH AGAINST is double in my query is just because i want to order my results (2nd time) and i want the score visible (1st time). I rename my MATCH AGAINST as Score, in order to get the score back out of the query. This would be something you could show on your page. Or do something with in your code.</p>
<p>If you want to limit the result by score, you have to add the following to the query:</p>
<p>HAVING score &gt; 2 (you can change the number in anything you want, but this will filter the worst results)</p>
<img src="http://feeds.feedburner.com/~r/phpz/~4/Lne8uyHzw4g" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.phpz.nl/?feed=rss2&amp;p=70</wfw:commentRss>
		<feedburner:origLink>http://www.phpz.nl/?p=70</feedburner:origLink></item>
		<item>
		<title>New function url_exists()</title>
		<link>http://feedproxy.google.com/~r/phpz/~3/dq4JTTbqRiQ/</link>
		<comments>http://www.phpz.nl/?p=63#comments</comments>
		<pubDate>Mon, 02 Mar 2009 02:09:27 +0000</pubDate>
		<dc:creator>Rene Pot</dc:creator>
		
		<category><![CDATA[PHP Problems]]></category>

		<category><![CDATA[Sugestions]]></category>

		<category><![CDATA[custom function]]></category>

		<category><![CDATA[file_exists]]></category>

		<category><![CDATA[function]]></category>

		<category><![CDATA[php]]></category>

		<category><![CDATA[solution]]></category>

		<guid isPermaLink="false">http://www.phpz.nl/?p=63</guid>
		<description><![CDATA[Function file_exists() is for files, but for url's there isn't a standard way to find out. Therefor a new url_exists() function.]]></description>
			<content:encoded><![CDATA[<p>We all know the function file_exists() to check if a file exists on the local server.<br />
But, if you want to check if an url is correct, this isn&#8217;t possible with this function.</p>
<p>Therefor i searched the web, and found this on php.net:</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;">        <span style="color: #000000; font-weight: bold;">function</span> url_exists<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$hdrs</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span>get_headers<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span>;
            <span style="color: #b1b100;">return</span> <span style="color: #990000;">is_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$hdrs</span><span style="color: #009900;">&#41;</span> ? <span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="">'/^HTTP<span style="">\\</span>/<span style="">\\</span>d+<span style="">\\</span>.<span style="">\\</span>d+<span style="">\\</span>s+2<span style="">\\</span>d<span style="">\\</span>d<span style="">\\</span>s+.*$/'</span><span style="color: #339933;">,</span><span style="color: #000088;">$hdrs</span><span style="color: #009900;">&#91;</span><span style="color:#800080;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">false</span>;
        <span style="color: #009900;">&#125;</span></pre></div></div>

<p>Didn&#8217;t think it would be that easy! Good luck with it <img src='http://www.phpz.nl/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /></p>
<img src="http://feeds.feedburner.com/~r/phpz/~4/dq4JTTbqRiQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.phpz.nl/?feed=rss2&amp;p=63</wfw:commentRss>
		<feedburner:origLink>http://www.phpz.nl/?p=63</feedburner:origLink></item>
		<item>
		<title>Custom new function mkfile()</title>
		<link>http://feedproxy.google.com/~r/phpz/~3/pwIkXZZjVfA/</link>
		<comments>http://www.phpz.nl/?p=54#comments</comments>
		<pubDate>Fri, 05 Dec 2008 12:59:47 +0000</pubDate>
		<dc:creator>Rene Pot</dc:creator>
		
		<category><![CDATA[Sugestions]]></category>

		<category><![CDATA[function]]></category>

		<category><![CDATA[make file]]></category>

		<category><![CDATA[mkfile]]></category>

		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.phpz.nl/?p=54</guid>
		<description><![CDATA[This new function makes it possible to create files and chmod them at the same time. This saves you a lot of writing in your code.]]></description>
			<content:encoded><![CDATA[<p>Since i needed to write a script that would make a file if it doesn&#8217;t excists, i thought mkfile() would be a perfect name for it.</p>
<p>The only thing mkfile does is check if a file excists on the server, and if it doesn&#8217;t it would create it, and chmod it. </p>
<p>Let me show you the code:</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> 
    <span style="color: #000000; font-weight: bold;">function</span> mkfile<span style="color: #009900;">&#40;</span><span style="color: #000088;">$filename</span><span style="color: #339933;">,</span><span style="color: #000088;">$mode</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$filename</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
             <span style="color: #000088;">$handle</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$filename</span><span style="color: #339933;">,</span><span style="">'w+'</span><span style="color: #009900;">&#41;</span>; 
             <span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #009900;">&#41;</span>;
             <span style="color: #990000;">chmod</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$filename</span><span style="color: #339933;">,</span><span style="color: #000088;">$mode</span><span style="color: #009900;">&#41;</span>; 
        <span style="color: #009900;">&#125;</span> 
    <span style="color: #009900;">&#125;</span> 
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>This code simply creates a function that can easily be used by calling it this way:</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> 
    mkfile<span style="color: #009900;">&#40;</span><span style="">'pages/myfile.php'</span><span style="color: #339933;">,</span><span style="color: #208080;">0777</span><span style="color: #009900;">&#41;</span>; 
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Just simply insert the filename and the rights (mode) and you can create a file with your own function.<br />
You can also add your own features to this function, but in my opinion it is already complete.</p>
<p>Note: Don&#8217;t forget to check the input in the mkfile() function. If you let users create files, you should at least know they wont enter scripts in it! But i made this function only for you&#8217;re own use!</p>
<img src="http://feeds.feedburner.com/~r/phpz/~4/pwIkXZZjVfA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.phpz.nl/?feed=rss2&amp;p=54</wfw:commentRss>
		<feedburner:origLink>http://www.phpz.nl/?p=54</feedburner:origLink></item>
		<item>
		<title>Read and Download a XML File</title>
		<link>http://feedproxy.google.com/~r/phpz/~3/DaLXaKQYPVc/</link>
		<comments>http://www.phpz.nl/?p=50#comments</comments>
		<pubDate>Tue, 28 Oct 2008 16:02:53 +0000</pubDate>
		<dc:creator>Rene Pot</dc:creator>
		
		<category><![CDATA[PHP Problems]]></category>

		<category><![CDATA[download]]></category>

		<category><![CDATA[file_put_contents]]></category>

		<category><![CDATA[local]]></category>

		<category><![CDATA[parse]]></category>

		<category><![CDATA[php]]></category>

		<category><![CDATA[read]]></category>

		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.phpz.nl/?p=50</guid>
		<description><![CDATA[How to read and store an external xml file localy. This is my solution.]]></description>
			<content:encoded><![CDATA[<p>I was working on a project when i needed to download an XML file and store it localy, to prevent slow scripts, because this XML file had 47 items. </p>
<p>When i would store it my script would work much faster! So i searched, and asked and found this:</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$geturl</span> <span style="color: #339933;">=</span> <span style="">'http://www.site.com/example.xml'</span>;
<span style="color: #000088;">$savelocal</span> <span style="color: #339933;">=</span> <span style="">'file.xml'</span>;
file_put_contents<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$savelocal</span><span style="color: #339933;">,</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$geturl</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>It is this simple and it works totaly fine!</p>
<img src="http://feeds.feedburner.com/~r/phpz/~4/DaLXaKQYPVc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.phpz.nl/?feed=rss2&amp;p=50</wfw:commentRss>
		<feedburner:origLink>http://www.phpz.nl/?p=50</feedburner:origLink></item>
		<item>
		<title>Get timestamps out of week no. and year.</title>
		<link>http://feedproxy.google.com/~r/phpz/~3/-vbivappiTI/</link>
		<comments>http://www.phpz.nl/?p=48#comments</comments>
		<pubDate>Thu, 23 Oct 2008 10:49:40 +0000</pubDate>
		<dc:creator>Rene Pot</dc:creator>
		
		<category><![CDATA[PHP Problems]]></category>

		<category><![CDATA[database]]></category>

		<category><![CDATA[date]]></category>

		<category><![CDATA[mysql]]></category>

		<category><![CDATA[php]]></category>

		<category><![CDATA[timestamp]]></category>

		<category><![CDATA[week]]></category>

		<category><![CDATA[weekno]]></category>

		<category><![CDATA[year]]></category>

		<guid isPermaLink="false">http://www.phpz.nl/?p=48</guid>
		<description><![CDATA[How to get the timestamp of monday and sunday out of a week number and a year.]]></description>
			<content:encoded><![CDATA[<p>Today i had a problem i only had a week number and a year. And i needed timestamps to get all results from a database in that week.</p>
<p>So, i searched on google and found this as first result:<br />
<a href="http://tzzz.wordpress.com/2006/08/14/8/">http://tzzz.wordpress.com/2006/08/14/8/</a></p>
<p>The code he provided wasn&#8217;t exactly what i have been looking for but in the comments there was a result that was very close.</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> getFirstDayOfWeek<span style="color: #009900;">&#40;</span><span style="color: #000088;">$year</span><span style="color: #339933;">,</span> <span style="color: #000088;">$weeknr</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
   <span style="color: #000088;">$offset</span> <span style="color: #339933;">=</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="">'w'</span><span style="color: #339933;">,</span> <span style="color: #990000;">mktime</span><span style="color: #009900;">&#40;</span><span style="color:#800080;">0</span><span style="color: #339933;">,</span><span style="color:#800080;">0</span><span style="color: #339933;">,</span><span style="color:#800080;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #000088;">$year</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
   <span style="color: #000088;">$offset</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$offset</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span> ? <span style="color: #cc66cc;">1</span><span style="color: #339933;">-</span><span style="color: #000088;">$offset</span> <span style="color: #339933;">:</span> <span style="color: #cc66cc;">8</span><span style="color: #339933;">-</span><span style="color: #000088;">$offset</span>;
   <span style="color: #000088;">$monday</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mktime</span><span style="color: #009900;">&#40;</span><span style="color:#800080;">0</span><span style="color: #339933;">,</span><span style="color:#800080;">0</span><span style="color: #339933;">,</span><span style="color:#800080;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">+</span><span style="color: #000088;">$offset</span><span style="color: #339933;">,</span><span style="color: #000088;">$year</span><span style="color: #009900;">&#41;</span>;
   <span style="color: #b1b100;">return</span> <span style="color: #990000;">strtotime</span><span style="color: #009900;">&#40;</span><span style="">'+'</span> <span style="color: #339933;">.</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$weeknr</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="">' weeks'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$monday</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now i changed this code to provide me the first and last day of the week:</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> getFirstDayOfWeek<span style="color: #009900;">&#40;</span><span style="color: #000088;">$year</span><span style="color: #339933;">,</span> <span style="color: #000088;">$weeknr</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000088;">$offset</span> <span style="color: #339933;">=</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="">'w'</span><span style="color: #339933;">,</span> <span style="color: #990000;">mktime</span><span style="color: #009900;">&#40;</span><span style="color:#800080;">0</span><span style="color: #339933;">,</span><span style="color:#800080;">0</span><span style="color: #339933;">,</span><span style="color:#800080;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #000088;">$year</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
    <span style="color: #000088;">$offset</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$offset</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span> ? <span style="color: #cc66cc;">1</span><span style="color: #339933;">-</span><span style="color: #000088;">$offset</span> <span style="color: #339933;">:</span> <span style="color: #cc66cc;">8</span><span style="color: #339933;">-</span><span style="color: #000088;">$offset</span>;
    <span style="color: #000088;">$monday</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mktime</span><span style="color: #009900;">&#40;</span><span style="color:#800080;">0</span><span style="color: #339933;">,</span><span style="color:#800080;">0</span><span style="color: #339933;">,</span><span style="color:#800080;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">+</span><span style="color: #000088;">$offset</span><span style="color: #339933;">,</span><span style="color: #000088;">$year</span><span style="color: #009900;">&#41;</span>;
    <span style="color: #000088;">$sunday</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mktime</span><span style="color: #009900;">&#40;</span><span style="color:#800080;">0</span><span style="color: #339933;">,</span><span style="color:#800080;">0</span><span style="color: #339933;">,</span><span style="color:#800080;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">7</span><span style="color: #339933;">+</span><span style="color: #000088;">$offset</span><span style="color: #339933;">,</span><span style="color: #000088;">$year</span><span style="color: #009900;">&#41;</span>;
&nbsp;
    <span style="color: #000088;">$day</span><span style="color: #009900;">&#91;</span><span style="">'first'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #990000;">strtotime</span><span style="color: #009900;">&#40;</span><span style="">'+'</span> <span style="color: #339933;">.</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$weeknr</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span>  <span style="">'weeks'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$monday</span><span style="color: #009900;">&#41;</span>;
    <span style="color: #000088;">$day</span><span style="color: #009900;">&#91;</span><span style="">'last'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #990000;">strtotime</span><span style="color: #009900;">&#40;</span><span style="">'+'</span> <span style="color: #339933;">.</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$weeknr</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="">' weeks'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$sunday</span><span style="color: #009900;">&#41;</span>;
&nbsp;
<span style="color: #b1b100;">return</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$day</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This solved my entire problem, so i could search my database with weeks without having it to store it in the database. That would be a solution that would cost me to much data.</p>
<img src="http://feeds.feedburner.com/~r/phpz/~4/-vbivappiTI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.phpz.nl/?feed=rss2&amp;p=48</wfw:commentRss>
		<feedburner:origLink>http://www.phpz.nl/?p=48</feedburner:origLink></item>
		<item>
		<title>MySQL issue with character set</title>
		<link>http://feedproxy.google.com/~r/phpz/~3/ZSxWJc5Yv7c/</link>
		<comments>http://www.phpz.nl/?p=46#comments</comments>
		<pubDate>Tue, 14 Oct 2008 09:46:24 +0000</pubDate>
		<dc:creator>Rene Pot</dc:creator>
		
		<category><![CDATA[PHP Problems]]></category>

		<category><![CDATA[Sugestions]]></category>

		<category><![CDATA[character]]></category>

		<category><![CDATA[encoding]]></category>

		<category><![CDATA[ezSQL]]></category>

		<category><![CDATA[php]]></category>

		<category><![CDATA[utf8]]></category>

		<guid isPermaLink="false">http://www.phpz.nl/?p=46</guid>
		<description><![CDATA[Today i stumbled upon an issue with inserting text into a database, and the character set wasn't taking it. This is my solution.]]></description>
			<content:encoded><![CDATA[<p>Today i stumbled upon an issue with inserting text into a database, and the character set wasn&#8217;t taking it. No mather what i changed in the database, it was inserted wrong time after time.</p>
<p>Characters like â and é are shown wrong. In the variable it is correct, but in database it isn&#8217;t.</p>
<p>This is what i had:</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
   <span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;é á â ê ô ç ö&quot;</span>;
   <span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; UPDATE mytable SET mytxt = '&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$string</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;' WHERE id=1&quot;</span><span style="color: #009900;">&#41;</span>; <span style="color: #666666; font-style: italic;">// using ezSQL</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>But when i looked into the database it wasn&#8217;t correct. Wrong encoding. The tabel was set UTF-8 so that couldn&#8217;t be wrong.</p>
<p>This was my solution:</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
   <span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;é á â ê ô ç ö&quot;</span>;
   <span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">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: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; UPDATE mytable SET mytxt = '&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$string</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;' WHERE id=1&quot;</span><span style="color: #009900;">&#41;</span>; <span style="color: #666666; font-style: italic;">// using ezSQL</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Now it was correct inserted, so i could use it properly.</p>
<img src="http://feeds.feedburner.com/~r/phpz/~4/ZSxWJc5Yv7c" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.phpz.nl/?feed=rss2&amp;p=46</wfw:commentRss>
		<feedburner:origLink>http://www.phpz.nl/?p=46</feedburner:origLink></item>
		<item>
		<title>Function Exists</title>
		<link>http://feedproxy.google.com/~r/phpz/~3/cQzrmMq-oFQ/</link>
		<comments>http://www.phpz.nl/?p=42#comments</comments>
		<pubDate>Mon, 06 Oct 2008 17:28:07 +0000</pubDate>
		<dc:creator>Rene Pot</dc:creator>
		
		<category><![CDATA[PHP Problems]]></category>

		<category><![CDATA[exists]]></category>

		<category><![CDATA[function]]></category>

		<category><![CDATA[function_exists]]></category>

		<category><![CDATA[php]]></category>

		<category><![CDATA[problem]]></category>

		<guid isPermaLink="false">http://www.phpz.nl/?p=42</guid>
		<description><![CDATA[how to use function exists. What do you use it for? It checks if you already declared a function.]]></description>
			<content:encoded><![CDATA[<p>Today i gotten into a problem. I am working on a project that supports multiple modules. And every module has it own functions. But sometimes a function is made double, because both modules need this function.<br />
But you never can be sure both modules are implemented in the website. So, you need to include them twice.</p>
<p>But because PHP gives an error when a function is double redeclared, they have brought up a solution. It&#8217;s called function_exists.<br />
Let me show you:</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="">'functionA'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
       <span style="color: #990000;">echo</span><span style="color: #009900;">&#40;</span><span style="">'It does'</span><span style="color: #009900;">&#41;</span>;
    <span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>This piece of code checks if functionA exists. But, ofcourse you want to use it so you will never include a double function. So you could use it this way:</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
   <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="">'functionA'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
       <span style="color: #000000; font-weight: bold;">function</span> functionA<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
           <span style="color: #990000;">echo</span><span style="color: #009900;">&#40;</span><span style="">'it does not'</span><span style="color: #009900;">&#41;</span>;
       <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Note the ! before function_exists. This turns an &#8220;if&#8221; into a &#8220;if not&#8221;. You can put it in front of every if quote.</p>
<img src="http://feeds.feedburner.com/~r/phpz/~4/cQzrmMq-oFQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.phpz.nl/?feed=rss2&amp;p=42</wfw:commentRss>
		<feedburner:origLink>http://www.phpz.nl/?p=42</feedburner:origLink></item>
	</channel>
</rss>
