<?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>Bright Cherry &#187; PHP</title>
	<atom:link href="http://www.brightcherry.co.uk/scribbles/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.brightcherry.co.uk/scribbles</link>
	<description></description>
	<lastBuildDate>Fri, 27 Aug 2010 18:00:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>PHP &#8211; Capitalize First Letter Of Every Sentence For Proper Formatting</title>
		<link>http://www.brightcherry.co.uk/scribbles/2010/07/31/php-capitalize-first-letter-of-every-sentence/</link>
		<comments>http://www.brightcherry.co.uk/scribbles/2010/07/31/php-capitalize-first-letter-of-every-sentence/#comments</comments>
		<pubDate>Sat, 31 Jul 2010 08:45:54 +0000</pubDate>
		<dc:creator>Maruf</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.brightcherry.co.uk/scribbles/?p=233</guid>
		<description><![CDATA[Here&#8217;s an extremely useful snippet of code that will properly format sentences with capitalization. Actually, what the code really does is capitialize every letter AFTER a full-stop (period). Here&#8217;s an example of what the code will do&#8230; Before: Hello This Is An Example Of A Sentence Which Has Odd Capitalization Which You May Want Fixing. [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s an extremely useful snippet of code that will properly format sentences with capitalization. Actually, what the code really does is capitialize every letter AFTER a full-stop (period). Here&#8217;s an example of what the code will do&#8230;</p>
<h4>Before:</h4>
<blockquote><p>
Hello This Is An Example Of A Sentence Which Has Odd Capitalization Which You May Want Fixing. tHere Are Problems With This Method, Which I Will disclose Shortly. If You Know How To Improve THis Code Please Let Me Know.
</p></blockquote>
<h4>After:</h4>
<blockquote><p>
Hello this is an example of a sentence which has odd capitalization which you may want fixing. There are problems with this method, which i will disclose shortly. If you know how to improve this code please let me know.
</p></blockquote>

<div class="wp_codebox_msgheader"><span class="right"><sup></sup></span><span class="left"><a rel="nofollow" href="javascript:;" onclick="javascript:showCodeTxt('p233code3'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p2333"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code" id="p233code3"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//define string</span>
<span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Hello This Is An Example Of A Sentence Which Has Odd Capitalization Which You May Want Fixing. tHere Are Problems With This Method, Which I Will disclose Shortly. If You Know How To Improve THis Code Please Let Me Know.&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//first we make everything lowercase, and then make the first letter if the entire string capitalized</span>
<span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #990000;">ucfirst</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strtolower</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//now we run the function to capitalize every letter AFTER a full-stop (period).</span>
<span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace_callback</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/[.!?].*?\w/'</span><span style="color: #339933;">,</span> <span style="color: #990000;">create_function</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'$matches'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'return strtoupper($matches[0]);'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//print the result</span>
<span style="color: #990000;">echo</span> <span style="color: #000088;">$string</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>There you have it. But there are flaws with this code, which you should be aware of.</p>
<h4>Recognised problems to consider</h4>
<p>This code will only capitalize the first letter of the string and all letters after full-stops (periods). Names, acronyms and countries will become lowercase when they should be capitalized.</p>
<p>Acronyms with full-stops won&#8217;t return as they should appear. For example, &#8220;e.g.&#8221; will return as &#8220;e.G.&#8221; because the G is directly after a full-stop.</p>
<p>A common problem is the word &#8220;I&#8221;, it will be returned in lowercase. For example, &#8220;You and i may have to make some exceptions&#8221;</p>
<h5>Solutions</h5>
<p>The way I overcome these issues by making rules with the str_replace function. Put these exceptions after the function has run and before printing the results. This isn&#8217;t an ideal solution for large lumps of data as there would be a lot of exceptions, but it&#8217;s useful for a manageable data size. You could, however, create your own function(s) to make the clean up process quicker and easier to handle large data.</p>
<h4>Possible solutions</h4>

<div class="wp_codebox_msgheader"><span class="right"><sup></sup></span><span class="left"><a rel="nofollow" href="javascript:;" onclick="javascript:showCodeTxt('p233code4'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p2334"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code" id="p233code4"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #666666; font-style: italic;">//to overcome the e.G. problem</span>
<span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;e.G.&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;e.g.&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//to overcome the lowercase i problem</span>
<span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; i &quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot; I &quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//to overcome the acronym problem</span>
<span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;dps&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;DPS&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Does anyone have any better solutions, or perhaps even improvements to the existing code?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.brightcherry.co.uk/scribbles/2010/07/31/php-capitalize-first-letter-of-every-sentence/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP &#8211; Populate Date Dropdowns &#8211; HTML Forms</title>
		<link>http://www.brightcherry.co.uk/scribbles/2010/06/10/php-create-dynamic-date-dropdowns/</link>
		<comments>http://www.brightcherry.co.uk/scribbles/2010/06/10/php-create-dynamic-date-dropdowns/#comments</comments>
		<pubDate>Thu, 10 Jun 2010 00:23:29 +0000</pubDate>
		<dc:creator>Maruf</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.brightcherry.co.uk/scribbles/?p=225</guid>
		<description><![CDATA[Ok, i&#8217;m going to quickly jot down some PHP code, which dynamically populates date fields (dd/mm/yyyy) for HTML forms. I&#8217;m always using this code, but I never write it down, so i&#8217;m forever retyping it! To generate the date dropdown fields shown above, you could hardcode the values, like this&#8230;. View Code HTML1 2 3 [...]]]></description>
			<content:encoded><![CDATA[<p>Ok, i&#8217;m going to quickly jot down some PHP code, which dynamically populates date fields (dd/mm/yyyy) for HTML forms. I&#8217;m always using this code, but I never write it down, so i&#8217;m forever retyping it!</p>
<p><img src="http://www.brightcherry.co.uk/images/blogimages/year_dropdown.jpg" title="Dynamic Date Dropdowns" alt="Dynamic Date Dropdowns" /></p>
<p>To generate the date dropdown fields shown above, you could hardcode the values, like this&#8230;.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup></sup></span><span class="left"><a rel="nofollow" href="javascript:;" onclick="javascript:showCodeTxt('p225code7'); return false;">View Code</a> HTML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p2257"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code" id="p225code7"><pre class="html" style="font-family:monospace;">&lt;select name=&quot;year&quot;&gt;
&lt;option value=&quot;1999&quot;&gt;1999&lt;/option&gt;
&lt;option value=&quot;2000&quot;&gt;2000&lt;/option&gt;
&lt;option value=&quot;2001&quot;&gt;2001&lt;/option&gt;
&lt;option value=&quot;2002&quot;&gt;2002&lt;/option&gt;
&lt;option value=&quot;2003&quot;&gt;2003&lt;/option&gt;
&lt;option value=&quot;2004&quot;&gt;2004&lt;/option&gt;
&lt;option value=&quot;2005&quot;&gt;2005&lt;/option&gt;
&lt;option value=&quot;2006&quot;&gt;2006&lt;/option&gt;
&lt;/select&gt;</pre></td></tr></table></div>

<p>But that&#8217;s a very tedious and long way of doing it. A better solution is to use a for loop in PHP to generate the dates. The following code i&#8217;m using automatically generates the dates with a few lines of PHP&#8230;</p>

<div class="wp_codebox_msgheader"><span class="right"><sup></sup></span><span class="left"><a rel="nofollow" href="javascript:;" onclick="javascript:showCodeTxt('p225code8'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p2258"><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
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
</pre></td><td class="code" id="p225code8"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>select name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;day&quot;</span><span style="color: #339933;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;?</span><span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$day</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #000088;">$day</span> <span style="color: #339933;">&lt;=</span> <span style="color: #cc66cc;">31</span><span style="color: #339933;">;</span> <span style="color: #339933;">++</span><span style="color: #000088;">$day</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #000000; font-weight: bold;">?&gt;</span>
		<span style="color: #000000; font-weight: bold;">&lt;?</span>
                <span style="color: #666666; font-style: italic;">//this code is adding a 0 before all values less than 10</span>
                <span style="color: #666666; font-style: italic;">//you don't need this code, but I prefer to have 2 digit values</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$day</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$day</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;0&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$day</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">?&gt;</span>
		<span style="color: #339933;">&lt;</span>option value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;?=<span style="color: #006699; font-weight: bold;">$day</span>?&gt;&quot;</span><span style="color: #339933;">&gt;&lt;</span>?<span style="color: #339933;">=</span><span style="color: #000088;">$day</span>?<span style="color: #339933;">&gt;&lt;/</span>option<span style="color: #339933;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;?</span><span style="color: #b1b100;">endfor</span><span style="color: #339933;">;</span>?<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>select<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>select name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;month&quot;</span><span style="color: #339933;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;?</span><span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$month</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #000088;">$month</span> <span style="color: #339933;">&lt;=</span> <span style="color: #cc66cc;">12</span><span style="color: #339933;">;</span> <span style="color: #339933;">++</span><span style="color: #000088;">$month</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #000000; font-weight: bold;">?&gt;</span>
		<span style="color: #000000; font-weight: bold;">&lt;?</span>
                <span style="color: #666666; font-style: italic;">//this code is adding a 0 before all values less than 10</span>
                <span style="color: #666666; font-style: italic;">//you don't need this code, but I prefer to have 2 digit values</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$month</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$month</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;0&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$month</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">?&gt;</span>
		<span style="color: #339933;">&lt;</span>option value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;?=<span style="color: #006699; font-weight: bold;">$month</span>?&gt;&quot;</span><span style="color: #339933;">&gt;&lt;</span>?<span style="color: #339933;">=</span><span style="color: #000088;">$month</span>?<span style="color: #339933;">&gt;&lt;/</span>option<span style="color: #339933;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;?</span><span style="color: #b1b100;">endfor</span><span style="color: #339933;">;</span>?<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>select<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>select name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;year&quot;</span><span style="color: #339933;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;?</span>
        <span style="color: #666666; font-style: italic;">//The 60 value here is the amount of years to go back</span>
	<span style="color: #000088;">$year</span> <span style="color: #339933;">=</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Y&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">60</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">//The 60 value here is the amount of years to go forward</span>
        <span style="color: #666666; font-style: italic;">//because i went back 60 years, i'm going forward 60 years so the dropdown will always have the current year, going back 60 years.</span>
	<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;=</span> <span style="color: #cc66cc;">60</span><span style="color: #339933;">;</span> <span style="color: #339933;">++</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #990000;">echo</span> <span style="color: #0000ff;">&quot;&lt;option&gt;<span style="color: #006699; font-weight: bold;">$year</span>&lt;/option&gt;&quot;</span><span style="color: #339933;">;</span> <span style="color: #339933;">++</span><span style="color: #000088;">$year</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #339933;">&lt;/</span>select<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>The above code will generate dropdowns for <b class="pink">day, month and year</b>! I&#8217;ve commented in areas where I felt appropriate.</p>
<p>Does anyone know a better way to do this with PHP? Would love to hear your tips&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.brightcherry.co.uk/scribbles/2010/06/10/php-create-dynamic-date-dropdowns/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP- Using Preg_replace To Strip Date From URL</title>
		<link>http://www.brightcherry.co.uk/scribbles/2009/09/18/php-using-preg_replace-to-strip-date-from-url/</link>
		<comments>http://www.brightcherry.co.uk/scribbles/2009/09/18/php-using-preg_replace-to-strip-date-from-url/#comments</comments>
		<pubDate>Fri, 18 Sep 2009 21:34:24 +0000</pubDate>
		<dc:creator>Maruf</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.brightcherry.co.uk/scribbles/?p=180</guid>
		<description><![CDATA[This is a very specific problem I was faced with a few days ago, so I doubt many people will find it directly useful. However, the solution to this problem can be used to resolve a load of tricky regular expression issues. The Scenerio A client recently changed permalink structures for his entire website. For [...]]]></description>
			<content:encoded><![CDATA[<p>This is a very specific problem I was faced with a few days ago, so I doubt many people will find it directly useful. However, the solution to this problem can be used to resolve a load of tricky regular expression issues.</p>
<h4>The Scenerio</h4>
<p>A client recently changed permalink structures for his entire website. For example, all his blog links were as follows:<br />
<b class="pink">http://www.example.com/blog/2009/12/09/example-blog-post/</b></p>
<p>For various reasons, the webmaster wanted to change the structure to:<br />
<b class="pink">http://www.example.com/blog/example-blog-post/</b> (stripping out the date)</p>
<p>The problem was, almost all the pages were internally linking to one another with the old URL structure, so the actual content of the page needed to be updated. In fact, in most cases, there were 4 or 5 links that needed to be updated on each page.</p>
<p>The webmaster didn&#8217;t want to manually modify each page because it would obviously take forever and a day. At first I thought it could be done with an MySQL query (page content is stored in a DB), but it actually can&#8217;t, so I had to create a PHP script to change all the links. The key function to enable this being <b class="pink">preg_replace</b>.</p>
<h4>The Solution</h4>

<div class="wp_codebox_msgheader"><span class="right"><sup></sup></span><span class="left"><a rel="nofollow" href="javascript:;" onclick="javascript:showCodeTxt('p180code10'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p18010"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code" id="p180code10"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// define the pattern you want to replace. The &quot;d&quot; is for &quot;digit&quot;, you can use &quot;w&quot; for alpanumeric</span>
<span style="color: #000088;">$pattern</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/example.co.uk\/blog\/(\d+)\/(\d+)\/(\d+)\//'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//define the placement</span>
<span style="color: #000088;">$replacement</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'example.co.uk/blog/'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;this is the string we want to replace &lt;a href=&quot;</span>http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//www.example.co.uk/blog/2009/12/09/example-blog-post&quot;&gt;link&lt;/a&gt;. More writing here &lt;a href=&quot;http://www.example.co.uk/blog/2009/12/09/example-blog-post&quot;&gt;link&lt;/a&gt;&quot;;</span>
&nbsp;
<span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pattern</span><span style="color: #339933;">,</span> <span style="color: #000088;">$replacement</span><span style="color: #339933;">,</span> <span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">echo</span> <span style="color: #000088;">$string</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//the output will be as follows:</span>
this is the string we want to replace <span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://www.example.co.uk/blog/example-blog-post&quot;</span><span style="color: #339933;">&gt;</span>link<span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;.</span> More writing here <span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://www.example.co.uk/blog/example-blog-post&quot;</span><span style="color: #339933;">&gt;</span>link<span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>And there you have it. Because it&#8217;s a regular expression function, the pattern is replaced EVERYTIME it is matched. The example above was the core function in the script I wrote. I actually used it in a while loop, to update a specific field in every row in a specific table, so each page was updated.</p>
<p>If anyone actually uses this example, please let me know how you get on with it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.brightcherry.co.uk/scribbles/2009/09/18/php-using-preg_replace-to-strip-date-from-url/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP- Call Action In A Loop On A Set Multiple Value</title>
		<link>http://www.brightcherry.co.uk/scribbles/2009/09/13/php-call-action-in-a-loop-on-a-set-multiple-value/</link>
		<comments>http://www.brightcherry.co.uk/scribbles/2009/09/13/php-call-action-in-a-loop-on-a-set-multiple-value/#comments</comments>
		<pubDate>Sun, 13 Sep 2009 11:46:16 +0000</pubDate>
		<dc:creator>Maruf</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.brightcherry.co.uk/scribbles/?p=176</guid>
		<description><![CDATA[This is one of those posts that is purely a reminder for myself. It&#8217;s something so simple, but for some reason or another, I tend to forget. Suppose I have a loop, and I want to call a certain action on every 5th loop. For example, on the 5th, 10th, 15th..etc count, I want to [...]]]></description>
			<content:encoded><![CDATA[<p>This is one of those posts that is purely a reminder for myself. It&#8217;s something so simple, but for some reason or another, I tend to forget. </p>
<p>Suppose I have a loop, and I want to call a certain action on every 5th loop. For example, on the 5th, 10th, 15th..etc count, I want to call an action.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup></sup></span><span class="left"><a rel="nofollow" href="javascript:;" onclick="javascript:showCodeTxt('p176code12'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p17612"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code" id="p176code12"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span>
<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">21</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</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: #000088;">$i</span> <span style="color: #339933;">%</span> <span style="color: #cc66cc;">5</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #990000;">echo</span> <span style="color: #0000ff;">&quot;Hello World&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>In the example above, &#8220;Hello World&#8221; will echo on the 5th, 10th, 15th and 20th count.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.brightcherry.co.uk/scribbles/2009/09/13/php-call-action-in-a-loop-on-a-set-multiple-value/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP- Getting The Filename From A URL</title>
		<link>http://www.brightcherry.co.uk/scribbles/2009/03/27/php-getting-the-filename-from-a-url/</link>
		<comments>http://www.brightcherry.co.uk/scribbles/2009/03/27/php-getting-the-filename-from-a-url/#comments</comments>
		<pubDate>Fri, 27 Mar 2009 11:56:27 +0000</pubDate>
		<dc:creator>Maruf</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.brightcherry.co.uk/scribbles/?p=81</guid>
		<description><![CDATA[Someone emailed me, asking me how to get the filename from a URL using PHP. It&#8217;s pretty easy, but I thought i&#8217;d jot it down for everyone, just in case other people want the same result. Example Ok, so we want the filename for the following page: http://www.anydomain.co.uk/page/grab.php We want to grab the filename, which [...]]]></description>
			<content:encoded><![CDATA[<p>Someone emailed me, asking me how to get the filename from a URL using PHP. It&#8217;s pretty easy, but I thought i&#8217;d jot it down for everyone, just in case other people want the same result.</p>
<h4>Example</h4>
<p>Ok, so we want the filename for the following page:</p>
<p>http://www.anydomain.co.uk/page/grab.php</p>
<p>We want to grab the filename, which is <b class="pink">grab.php</b></p>
<p>The following code will do that for you:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup></sup></span><span class="left"><a rel="nofollow" href="javascript:;" onclick="javascript:showCodeTxt('p81code15'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p8115"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p81code15"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$basename</span> <span style="color: #339933;">=</span> <span style="color: #990000;">basename</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REQUEST_URI'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>If you want to remove the .php, a simple string replace function will do:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup></sup></span><span class="left"><a rel="nofollow" href="javascript:;" onclick="javascript:showCodeTxt('p81code16'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p8116"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p81code16"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$basename</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;.php&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span><span style="color: #990000;">basename</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REQUEST_URI'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>And that&#8217;s it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.brightcherry.co.uk/scribbles/2009/03/27/php-getting-the-filename-from-a-url/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
