<?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>php-snippets &#8211; Extreme Web Designs</title>
	<atom:link href="https://theextremewebdesigns.com/blog/tag/php-snippets/feed/" rel="self" type="application/rss+xml" />
	<link>https://theextremewebdesigns.com/blog</link>
	<description>Web Design and Web Development</description>
	<lastBuildDate>Sat, 04 Feb 2012 03:10:26 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.5</generator>
<site xmlns="com-wordpress:feed-additions:1">156673191</site>	<item>
		<title>PHP: Time difference Facebook Twitter style</title>
		<link>https://theextremewebdesigns.com/blog/php-time-difference-facebook-twitter-style/</link>
					<comments>https://theextremewebdesigns.com/blog/php-time-difference-facebook-twitter-style/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sat, 04 Feb 2012 03:10:26 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Snippets]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[php-snippets]]></category>
		<category><![CDATA[php-tips]]></category>
		<guid isPermaLink="false">https://theextremewebdesigns.com/blog/?p=166</guid>

					<description><![CDATA[If you ever wanted to display the time elapsed in Facebook or Twitter style (recall the format: 20 minutes ago, 100 days ago?). Here is a handy little snippet in PHP, that will let you do exactly the same. How to show Time difference using Facebook Twitter style In order to show the time difference [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>If you ever wanted to display the time elapsed in Facebook or Twitter style (recall the format: 20 minutes ago, 100 days ago?). Here is a handy little snippet in PHP, that will let you do exactly the same.<span id="more-166"></span></p>
<h2>How to show Time difference using Facebook Twitter style</h2>
<div class="make_demo">

	<form action="https://theextremewebdesigns.com/blog/wp-content/themes/ewd_blog_2017/try_demo.php?post_id=166" method="post" name="form1" target="_blank" id="form1">


	<input type="hidden" name="shortcode_content" id="shortcode_content" value="" />

        <div class="try_demo_btn_container">


            <button type="submit" name="sbt_make_demo" id="sbt_make_demo" class="btn-primary btn-try-demo">
                Try Demo
            </button>


        </div><!-- .try_demo_btn_container -->

    </form>
    </div>
    
<p>In order to show the time difference in Facebook Twitter style using PHP, use the following code:</p>
<pre class="lang:php decode:true">&lt;?php

function time_difference($date)
{
if(empty($date)) {
return "Please provide date.";
}

$periods = array("second", "minute", "hour", "day", "week", "month", "year", "decade");
$lengths = array("60","60","24","7","4.35","12","10");

$now = time();
$unix_date = strtotime($date);

// check validity of date
if(empty($unix_date)) {
return "Invalid date";
}

//Check to see if it is past date or future date
if($now &gt; $unix_date) {
$difference = $now - $unix_date;
$tense = "ago";

} else {
$difference = $unix_date - $now;
$tense = "from now";
}

for($j = 0; $difference &gt;= $lengths[$j] &amp;&amp; $j &lt; count($lengths)-1; $j++) {
$difference /= $lengths[$j];
}

$difference = round($difference);

if($difference != 1) {
$periods[$j].= "s";
}

return "$difference $periods[$j] {$tense}";
}

//Current date and time
$current_date = date("Y-m-d G:i");
echo 'Current Date: '.$current_date.'&lt;br /&gt;';
$elapsed_time = time_difference($current_date);
echo $elapsed_time.'&lt;br /&gt;';
//Ouputs: 53 seconds ago

//Past date and time
$past_date = date("2010-1-1 12:00");
$elapsed_time = time_difference($past_date);
echo $elapsed_time.'&lt;br /&gt;';
//Ouputs: 2 years ago

//Future date and time
$future_date = date("2013-1-1 12:00");
$elapsed_time = time_difference($future_date);
echo $elapsed_time.'&lt;br /&gt;';
//Ouputs: 11 months from now
?&gt;</pre>
<div class="make_demo">

	<form action="https://theextremewebdesigns.com/blog/wp-content/themes/ewd_blog_2017/try_demo.php?post_id=166" method="post" name="form1" target="_blank" id="form1">


	<input type="hidden" name="shortcode_content" id="shortcode_content" value="" />

        <div class="try_demo_btn_container">


            <button type="submit" name="sbt_make_demo" id="sbt_make_demo" class="btn-primary btn-try-demo">
                Try Demo
            </button>


        </div><!-- .try_demo_btn_container -->

    </form>
    </div>
    
<h5>That’s it!</h5>
<p>Do you know of any other ways to <strong>display the time difference in Facebook/Twitter style</strong>? If yes, we would love to hear from you. Please leave your comments below.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://theextremewebdesigns.com/blog/php-time-difference-facebook-twitter-style/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">166</post-id>	</item>
		<item>
		<title>PHP: Add Date, Months, Years to current date</title>
		<link>https://theextremewebdesigns.com/blog/php-add-date-months-years-to-current-date/</link>
					<comments>https://theextremewebdesigns.com/blog/php-add-date-months-years-to-current-date/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sat, 04 Feb 2012 02:27:10 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Snippets]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[php-snippets]]></category>
		<category><![CDATA[php-tips]]></category>
		<guid isPermaLink="false">https://theextremewebdesigns.com/blog/?p=143</guid>

					<description><![CDATA[Did you ever want to add date, months or years to current date in PHP but never figured out how to? Well, this little snippet can come in handy. PHP Add Date, Months, Years to current date //For simplicity, I have selected American date format as I am used to it. //You may select any [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Did you ever want to add date, months or years to current date in PHP but never figured out how to? Well, this little snippet can come in handy.<span id="more-143"></span></p>
<p><strong>PHP Add Date, Months, Years to current date</strong></p>
<pre class="lang:php decode:true">//For simplicity, I have selected American date format as I am used to it.
//You may select any format that your application uses, such as date("d-m-Y")
//or date("Y-m-d"), etc.

$current_date = date("m-d-Y");
echo "Current Date: ".$current_date."&lt;br /&gt;";

//Add 1 Day to current date i.e. today
$add_day = strtotime(date("m-d-Y", strtotime($current_date)) . "+1 day");
echo "After adding 1 Day: ".date('m-d-y', $add_day)."&lt;br /&gt;";
//Add 10 Days to current date
$add_days = strtotime(date("m-d-Y", strtotime($current_date)) . "+10 day");
echo "After adding 10 Days: ".date('m-d-Y', $add_days)."&lt;br /&gt;";

//Add 1 Month to current date
$add_month = strtotime(date("m-d-Y", strtotime($current_date)) . "+1 month");
echo "After adding 1 Month: ".date('m-d-Y', $add_month)."&lt;br /&gt;";
//Add 10 Months to current date
$add_months = strtotime(date("m-d-Y", strtotime($current_date)) . "+10 month");
echo "After adding 10 Months: ".date('m-d-Y', $add_months)."&lt;br /&gt;";

//Add 1 Year to current date
$add_year = strtotime(date("m-d-Y", strtotime($current_date)) . "+1 year");
echo "After adding 1 Year: ".date('m-d-Y', $add_year)."&lt;br /&gt;";
//Add 10 Years to current date
$add_years = strtotime(date("m-d-Y", strtotime($current_date)) . "+10 year");
echo "After adding 10 Years: ".date('m-d-Y', $add_years)."&lt;br /&gt;";

//Results:
Current Date: 02-04-2012
After adding 1 Day: 02-05-12
After adding 10 Days: 02-14-2012
After adding 1 Month: 03-04-2012
After adding 10 Months: 12-04-2012
After adding 1 Year: 02-04-2013
After adding 10 Years: 02-04-2022</pre>
<p><strong>That&#8217;s it!</strong></p>
<p>I am sure that there are other ways to do this. Do you know of any other ways to <strong>add date, month and year using PHP</strong>? If yes, we would love to hear from you. Please leave your comments below.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://theextremewebdesigns.com/blog/php-add-date-months-years-to-current-date/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">143</post-id>	</item>
		<item>
		<title>PHP Validate Twitter Username Example</title>
		<link>https://theextremewebdesigns.com/blog/php-validate-twitter-username/</link>
					<comments>https://theextremewebdesigns.com/blog/php-validate-twitter-username/#comments</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sat, 04 Feb 2012 00:18:53 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Snippets]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[php-snippets]]></category>
		<category><![CDATA[php-tips]]></category>
		<guid isPermaLink="false">https://theextremewebdesigns.com/blog/?p=137</guid>

					<description><![CDATA[If you want to validate Twitter username using PHP i.e check whether its available for registration or not, this can be easily achieved using CURL. The following function will check whether twitter username exists for registration or if it is already registered. How to Validate Twitter Username using PHP Use the following code to validate Twitter Username [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>If you want to validate Twitter username using PHP i.e check whether its available for registration or not, this can be easily achieved using CURL. The following function will check whether twitter username exists for registration or if it is already registered.<span id="more-137"></span></p>
<h2>How to Validate Twitter Username using PHP</h2>
<p>Use the following code to validate Twitter Username using PHP:</p>
<pre class="lang:php decode:true">&lt;?php
function validate_twitter_username($username)
{
$twitter_url='http://api.twitter.com/1/users/show/'.$username.'.xml';

$init = curl_init();
curl_setopt ($init, CURLOPT_URL, $twitter_url);
curl_setopt ($init, CURLOPT_CONNECTTIMEOUT, 20);
curl_setopt($init, CURLOPT_NOBODY, 1);
curl_setopt($init, CURLOPT_HEADER, 1);
curl_setopt($init, CURLOPT_RETURNTRANSFER, true);

curl_exec($init);
$result_header = curl_getinfo($init, CURLINFO_HTTP_CODE);
curl_close($init);

// IF username does note exist, then it means its avilable for registration
if( '404' == $result_header )
{
return 'Username is available.';
}
else
{
// This means username is already taken
return 'Username already taken.';
}
}

//Enter the username you want to check below and that's it.
$username = 'extreme';

echo validate_twitter_username($username);
?&gt;</pre>
<h5>That&#8217;s it!</h5>
<p>Do you know a simpler way to <strong>validate twitter username?</strong> If yes, please share it with us in your comments below.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://theextremewebdesigns.com/blog/php-validate-twitter-username/feed/</wfw:commentRss>
			<slash:comments>13</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">137</post-id>	</item>
	</channel>
</rss>
