uly.me

cloud engineer

  • Home
  • Category
    • Cloud
    • PHP
    • Linux
    • HTML
    • WP
    • CSS
    • SVN
    • Mac
    • Git
    • JS
    • Misc
  • About
    • Me
    • Archives
    • Contact
    • Portfolio
    • Podcasts
  • Code
    • Github
    • Docker Hub
    • Unfuddle
You are here: Home / 2014 / Archives for February 2014

Archives for February 2014

February 27, 2014

SimplePie RSS Reader

If you’re thinking about adding syndication to your website, consider using SimplePie, a super fast and easy-to-use feed parser written in PHP. With SimplePie, adding a RSS feed to your site couldn’t be more easier. In this article, I will show you how to create a RSS page that will display a feed. It will display my blog’s RSS feed as default when nothing is clicked. I’ve included a couple of links that are clickable. When the links are clicked, the RSS feed for that link will be displayed.

First, download SimplePie.

Next, we need to create a file and copy the code below. The code is pretty much self-explanatory.

<?php 
// include SimplePie
require_once('php/autoloader.php');
 
// Create a new object called $feed
$feed = new SimplePie();
 
// Set the default to my blog's RSS at first run
if ($_GET[feed] == "") { $_GET[feed]="http://uly.me/feed/"; }
$feed->set_feed_url($_GET[feed]);
 
// Run SimplePie.
$feed->init();
 
// Send the result to show up on the browser
$feed->handle_content_type();
?>
 
<!-- Display the links -->
<a href="rssfeed.php?feed=http://news.yahoo.com/rss">Yahoo News</a> | 
<a href="rssfeed.php?feed=http://feeds.reuters.com/reuters/topNews">Reuter News</a>
 
<!-- Display the header -->
<div class="header">
  <h1><a href="<?php echo $feed->get_permalink(); ?>"><?php echo $feed->get_title(); ?></a></h1>
  <p><?php echo $feed->get_description(); ?></p>
</div>
 
<?php
// Display the feed inside a loop
foreach ($feed->get_items() as $item): ?>
<div class="item">
<li><a href="<?php echo $item->get_permalink(); ?>" target="_blank"><?php echo $item->get_title(); ?></a></li>
  <p><?php echo $item->get_description(); ?></p>
  <p><small>Posted on <?php echo $item->get_date('j F Y | g:i a'); ?></small></p>
</div>
<?php 
endforeach;
 
/* end of file */

<?php // include SimplePie require_once('php/autoloader.php'); // Create a new object called $feed $feed = new SimplePie(); // Set the default to my blog's RSS at first run if ($_GET[feed] == "") { $_GET[feed]="http://uly.me/feed/"; } $feed->set_feed_url($_GET[feed]); // Run SimplePie. $feed->init(); // Send the result to show up on the browser $feed->handle_content_type(); ?> <!-- Display the links --> <a href="rssfeed.php?feed=http://news.yahoo.com/rss">Yahoo News</a> | <a href="rssfeed.php?feed=http://feeds.reuters.com/reuters/topNews">Reuter News</a> <!-- Display the header --> <div class="header"> <h1><a href="<?php echo $feed->get_permalink(); ?>"><?php echo $feed->get_title(); ?></a></h1> <p><?php echo $feed->get_description(); ?></p> </div> <?php // Display the feed inside a loop foreach ($feed->get_items() as $item): ?> <div class="item"> <li><a href="<?php echo $item->get_permalink(); ?>" target="_blank"><?php echo $item->get_title(); ?></a></li> <p><?php echo $item->get_description(); ?></p> <p><small>Posted on <?php echo $item->get_date('j F Y | g:i a'); ?></small></p> </div> <?php endforeach; /* end of file */

See the demo. Just add your own CSS stylesheet and you’re ready to go.

Filed Under: PHP Tagged With: feed, rss, simplepie

February 26, 2014

Calculating Dates in PHP

Calculating and formatting dates is an important function when writing software applications. You might be needing to perform a database search of all transactions a month ago, six months ago, etc. To make this all possible, you need to be able to figure out how to calculate dates based from today’s date. PHP has a couple of date functions called date() and mktime(). I use the date() function primarily for formatting dates, and mktime() function for calculating dates since mktime() is the actual Unix timestamp. With these two functions, you can do some pretty amazing date calculations.

Let’s get started.

// Today's date
$day   = date("d");
$month = date("m");
$year  = date("Y");
 
// Using mktime calculate past dates
$start_of_three_months_ago = mktime(0, 0, 0, date("m")-2, 1, date("Y"));
$end_of_three_months_ago   = mktime(23, 59, 59, date("m")-1, 0, date("Y"));
 
// Using mktime to calculate future dates
$start_of_three_months_from_now = mktime(0, 0, 0, date("m")+3, 1, date("Y"));
$end_of_three_months_from_now   = mktime(23, 59, 59, date("m")+4, 0, date("Y"));
 
// Formatting dates to 'month day, year' format.
$a = date("M j, Y", $start_of_three_months_ago);
$b = date("M j, Y", $end_of_three_months_ago);
$c = date("M j, Y", $start_of_three_months_from_now);
$d = date("M j, Y", $end_of_three_months_from_now);
 
// results are based on today's date 
echo $day;
// results in 26
echo $month;
// results in 02
echo $year;
// results in 2014
echo $a;
// results in Dec 1, 2013
echo $b;
// results in Dec 31, 2014
echo $c;
// results in May 1, 2014
echo $d;
// results in May 31, 2014

// Today's date $day = date("d"); $month = date("m"); $year = date("Y"); // Using mktime calculate past dates $start_of_three_months_ago = mktime(0, 0, 0, date("m")-2, 1, date("Y")); $end_of_three_months_ago = mktime(23, 59, 59, date("m")-1, 0, date("Y")); // Using mktime to calculate future dates $start_of_three_months_from_now = mktime(0, 0, 0, date("m")+3, 1, date("Y")); $end_of_three_months_from_now = mktime(23, 59, 59, date("m")+4, 0, date("Y")); // Formatting dates to 'month day, year' format. $a = date("M j, Y", $start_of_three_months_ago); $b = date("M j, Y", $end_of_three_months_ago); $c = date("M j, Y", $start_of_three_months_from_now); $d = date("M j, Y", $end_of_three_months_from_now); // results are based on today's date echo $day; // results in 26 echo $month; // results in 02 echo $year; // results in 2014 echo $a; // results in Dec 1, 2013 echo $b; // results in Dec 31, 2014 echo $c; // results in May 1, 2014 echo $d; // results in May 31, 2014

You can then use any set of dates to calculate transactions on the database. For example.

SELECT price FROM product WHERE purchase_date BETWEEN $a AND $b;

SELECT price FROM product WHERE purchase_date BETWEEN $a AND $b;

Read more about PHP’s date and mktime functions. See demo. Results are based on today’s date.

Filed Under: PHP Tagged With: date, mktime

February 25, 2014

The Latest Speed Test

The Latest Speed Test

I recently switched to Comcast for my Internet services. It has been several years since I have left and abandoned Comcast. I was curious more than anything as to what kind of download speeds I’ll be getting now that I’m back to using broadband cable. The result is pretty impressive. It has been a while since I’ve seen this kind of speeds at home. It’s about 4-5 times faster than what I previously had. I ran 3 different speed tests from 3 different sources. I’m a little surprised the results were similar. All fell within the same range of one another. So, without much further ado, here are the results of the speed tests.

Comcast Speed Test

speedtest

Speakeasy

speakeasy

Speedtest

speedtest-net

Filed Under: Misc Tagged With: comcast, speedtest

  • 1
  • 2
  • 3
  • 4
  • Next Page »

Subscribe

Cloud

  • Extend an EBS Volume
  • Convert JSON to YAML
  • AWS S3 Killedted
  • Serverless Jekyll on AWS
  • AWS and VMWare

Linux

  • Cronjob Not Running
  • Password Expiry
  • Multiple VirtualHosts
  • Convert JSON to YAML
  • Empty A File

PHP

  • Comparing Time
  • Quick Database Check
  • Laravel 5.4 Install
  • Mass Find and Replace
  • WordPress Mobile Detect

Copyright © 2018. All rights reserved.