<?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>bavotasan.com &#187; Php Function</title>
	<atom:link href="http://bavotasan.com/tag/php-function/feed/" rel="self" type="application/rss+xml" />
	<link>http://bavotasan.com</link>
	<description>by c.bavota</description>
	<lastBuildDate>Tue, 07 Feb 2012 15:42:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Using PHP to Remove an HTML Tag from a String</title>
		<link>http://bavotasan.com/2009/using-php-to-remove-an-html-tag-from-a-string/</link>
		<comments>http://bavotasan.com/2009/using-php-to-remove-an-html-tag-from-a-string/#comments</comments>
		<pubDate>Tue, 01 Dec 2009 21:54:49 +0000</pubDate>
		<dc:creator>c.bavota</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[Function]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[Image Tag]]></category>
		<category><![CDATA[Php]]></category>
		<category><![CDATA[Php Function]]></category>
		<category><![CDATA[piece]]></category>
		<category><![CDATA[Preg]]></category>
		<category><![CDATA[Remove]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[tag]]></category>
		<category><![CDATA[way]]></category>

		<guid isPermaLink="false">http://bavotasan.com/?p=1555</guid>
		<description><![CDATA[There are times when you need to strip one specific HTML tag from a string and the PHP function strip_tags() doesn&#8217;t work the way you want it to. strip_tags() allows for certain exclusions, but why would you use that when you only want to exclude one tag and include all other tags? Especially when you [...]]]></description>
			<content:encoded><![CDATA[<p>There are times when you need to strip one specific HTML tag from a string and the PHP function <code>strip_tags()</code> doesn&#8217;t work the way you want it to.  <code>strip_tags()</code> allows for certain exclusions, but why would you use that when you only want to exclude one tag and include all other tags? Especially when you can use <code>preg_replace()</code>.<br />
<span id="more-1555"></span><br />
Here is a quick little piece of code that can be modified for any specific HTML tag you want to remove from a string. I am using it below to remove an image tag.</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="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;">'Here is your content with an image tag &lt;img src=&quot;http://bavotasan.com/wp-content/themes/bavotasan_new/images/bavota.png&quot; alt=&quot;Image&quot; /&gt;'</span> <span style="color: #339933;">;</span>
<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: #0000ff;">&quot;/&lt;img[^&gt;]+\&gt;/i&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;&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: #b1b100;">echo</span> <span style="color: #000088;">$string</span> <span style="color: #666666; font-style: italic;">// will output &quot;Here is your content with an image tag&quot; without the image tag</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></td></tr></table></div>

<p>You can replace the <code>img</code> in the <code>preg_replace()</code> function for it to work with whichever HTML tag you wish.</p>
]]></content:encoded>
			<wfw:commentRss>http://bavotasan.com/2009/using-php-to-remove-an-html-tag-from-a-string/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to List Your Most Popular Posts in WordPress</title>
		<link>http://bavotasan.com/2009/how-to-list-your-most-popular-posts-in-wordpress/</link>
		<comments>http://bavotasan.com/2009/how-to-list-your-most-popular-posts-in-wordpress/#comments</comments>
		<pubDate>Tue, 19 May 2009 21:47:39 +0000</pubDate>
		<dc:creator>c.bavota</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Background Url]]></category>
		<category><![CDATA[desc]]></category>
		<category><![CDATA[Foreach]]></category>
		<category><![CDATA[h2]]></category>
		<category><![CDATA[Images]]></category>
		<category><![CDATA[Padding]]></category>
		<category><![CDATA[Php Function]]></category>
		<category><![CDATA[Png]]></category>
		<category><![CDATA[serif]]></category>
		<category><![CDATA[Sidebar]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://bavotasan.com/?p=576</guid>
		<description><![CDATA[I decided my sidebar was looking a little plain. It needed something more than just ads, so I placed a list of my popular posts there. I think it looks pretty cool and it was very simple to do. I just created a PHP function and added it to my functions.php files and then added [...]]]></description>
			<content:encoded><![CDATA[<p>I decided my sidebar was looking a little plain. It needed something more than just ads, so I placed a list of my popular posts there. I think it looks pretty cool and it was very simple to do. I just created a PHP function and added it to my functions.php files and then added some styles to get it to look the way I wanted.<br />
<span id="more-576"></span><br />
First lets create the function. We&#8217;ll call it popularPosts. Be sure to add it between <?php and ?> tags.</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> popularPosts<span style="color: #009900;">&#40;</span><span style="color: #000088;">$num</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$posts</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_results</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT comment_count, ID, post_title FROM <span style="color: #006699; font-weight: bold;">$wpdb-&gt;posts</span> ORDER BY comment_count DESC LIMIT 0 , <span style="color: #006699; font-weight: bold;">$num</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$posts</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$post</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        setup_postdata<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$title</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_title</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$count</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">comment_count</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$count</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: #000088;">$popular</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;li&gt;'</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$popular</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;a href=&quot;'</span> <span style="color: #339933;">.</span> get_permalink<span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot; title=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$title</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot;&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$title</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/a&gt; '</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$popular</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;/li&gt;'</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$popular</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></td></tr></table></div>

<p>Now to call the function, all we need to do is place this code wherever we want our list to appear. Let&#8217;s call for a list of 10 items by placing a &#8217;10&#8242; as our $num variable when we call our function.</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;">&lt;div class=&quot;popular&quot;&gt;
    &lt;h2&gt;Most Popular Posts&lt;/h2&gt;
    &lt;ul&gt;
        <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> popularPosts<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
    &lt;/ul&gt;
&lt;/div&gt;</pre></div></td></tr></table></div>

<p>All that is left is some styles to make it look good. Here are the styles I used for my sidebar list.</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.popular</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">clear</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">both</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">283px</span><span style="color: #00AA00;">;</span>
	<span style="color: #00AA00;">&#125;</span>
&nbsp;
	<span style="color: #6666ff;">.popular</span> ul<span style="color: #00AA00;">,</span> <span style="color: #6666ff;">.popular</span> ul li <span style="color: #00AA00;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
		<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
		<span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">12px</span><span style="color: #00AA00;">;</span>
		<span style="color: #00AA00;">&#125;</span>
&nbsp;
		<span style="color: #6666ff;">.popular</span> ul li <span style="color: #00AA00;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #933;">4px</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
			<span style="color: #000000; font-weight: bold;">padding-left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">20px</span><span style="color: #00AA00;">;</span>
			<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">images/star.png</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</span> <span style="color: #933;">2px</span> <span style="color: #933;">2px</span><span style="color: #00AA00;">;</span>
			<span style="color: #00AA00;">&#125;</span>
&nbsp;
	<span style="color: #6666ff;">.popular</span> h2 <span style="color: #00AA00;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
		<span style="color: #000000; font-weight: bold;">border-bottom</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#aaa</span><span style="color: #00AA00;">;</span>
		<span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">22px</span><span style="color: #00AA00;">;</span>
		<span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">normal</span><span style="color: #00AA00;">;</span>
		<span style="color: #000000; font-weight: bold;">font-family</span><span style="color: #00AA00;">:</span> Georgia<span style="color: #00AA00;">,</span><span style="color: #993333;">serif</span><span style="color: #00AA00;">;</span>
		<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">15px</span><span style="color: #00AA00;">;</span>
		<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">5px</span><span style="color: #00AA00;">;</span>
		<span style="color: #00AA00;">&#125;</span></pre></div></td></tr></table></div>

<p>For the star, I used this image <img src="http://bavotasan.com/wp-content/themes/bavotasan_new/images/star.png" alt="star" /> which I created in Illustartor.</p>
<p>Just right click above or drag the image to your desktop and add it to the appropriate directory to complete the look. You can also replace that image with whatever you want to appear there.</p>
]]></content:encoded>
			<wfw:commentRss>http://bavotasan.com/2009/how-to-list-your-most-popular-posts-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>36</slash:comments>
		</item>
		<item>
		<title>Add Time to the Date Function in PHP</title>
		<link>http://bavotasan.com/2009/add-time-to-the-date-function-in-php/</link>
		<comments>http://bavotasan.com/2009/add-time-to-the-date-function-in-php/#comments</comments>
		<pubDate>Wed, 22 Apr 2009 21:36:07 +0000</pubDate>
		<dc:creator>c.bavota</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[client]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[expiration]]></category>
		<category><![CDATA[Function]]></category>
		<category><![CDATA[month]]></category>
		<category><![CDATA[Php]]></category>
		<category><![CDATA[Php Function]]></category>
		<category><![CDATA[Programmers]]></category>
		<category><![CDATA[site]]></category>
		<category><![CDATA[something]]></category>
		<category><![CDATA[time]]></category>
		<category><![CDATA[today]]></category>
		<category><![CDATA[user]]></category>

		<guid isPermaLink="false">http://bavotasan.com/?p=541</guid>
		<description><![CDATA[I just needed to do this for a client&#8217;s site to set an expiration date for a user and I thought it might be something that other programmers might like to know how to do. If you need to take today&#8217;s date and add time to it it is pretty simple. There is a PHP [...]]]></description>
			<content:encoded><![CDATA[<p>I just needed to do this for a client&#8217;s site to set an expiration date for a user and I thought it might be something that other programmers might like to know how to do. If you need to take today&#8217;s date and add time to it it is pretty simple. There is a PHP function called date() and another called strtotime(). You need to use both to make this happen.<br />
<span id="more-541"></span></p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$date</span> <span style="color: #339933;">=</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Y-m-d'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$timestamp</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strtotime</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Y-m-d&quot;</span><span style="color: #339933;">,</span> <span style="color: #990000;">strtotime</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$date</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot; + 1 month&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$expired</span> <span style="color: #339933;">=</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Y-m-d'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$timestamp</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></td></tr></table></div>

<p>If you echoed out $date you would get today&#8217;s date formatted like &#8220;2009-04-21&#8243;.</p>
<p>If you echoed out $expired you would get today&#8217;s date plus 1 month, formatted like &#8220;2009-05-21&#8243;.</p>
<p>You can replace the &#8220;1 month&#8221; with &#8220;14 days&#8221; or &#8220;2 years&#8221; or whichever increment you need.</p>
]]></content:encoded>
			<wfw:commentRss>http://bavotasan.com/2009/add-time-to-the-date-function-in-php/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

