Tech Tips

Display Featured Links Randomly Using PHP

Posted on June 29, 2009. Filed under: Main, Tech Tips, Web Development, Work Links | Tags: , , , , , , |

I had a request to add a "Link of the Day" feature to one of the pages on the Law-related Education pages of the OBA Web site using what we currently have in place.  I’m sure there are widgets out there already that will do this for me, and it may even be built into whatever CMS we deploy next, but I wanted to learn a bit so I decided to implement it on our current site.  I don’t know much about PHP, but I learned to code in VB.NET and C++, so I can learn enough as I go to make things work.

With the help of The Google, I was able to piece together a little bit of code that reads from a CSV file into an array, then randomly displays a link from within that array on each page load, so that a new link is loaded on each visit.

The original code has appeared in several forms across the Internet already, so if it’s yours, please let me know so I can credit you.  I’ve made some slight adjustments to fit my needs.


  1: <?php
  2: function makeClickableLinks($text) {
  3:  
  4:   $text = eregi_replace('(((f|ht){1}(tp|tps)://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)',
  5:     '\\1', $text);
  6:   $text = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)',
  7:     '\\1\\2', $text);
  8:   $text = eregi_replace('([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})',
  9:     '\\1', $text);
 10:   
 11: return $text;
 12:  
 13: } // end function
 14: 
 15: 
 16: function displayLink(){
 17: 
 18: $fp = fopen("your-file.csv", "r");
 19: while (!feof ($fp)) {
 20: $contents[] = explode(",", fgets($fp, 512));
 21: }
 22: fclose ($fp);
 23: 
 24: do {
 25: 	$x = rand(0, count($contents)-1);
 26: 		} while ($contents[$x] == '0');
 27: 
 28: // displays link title above clickable URL
 29: echo $contents[$x][0] . "<br />\n" . makeClickableLinks($contents[$x][1]) . "<br />\n";
 30: 
 31: // displays link title as clickable link
 32: echo '<a href="' . $contents[$x][1] . '" rel="nofollow">' . $contents[$x][0] . '</a>';
 33: 
 34: } // end function
 35: 
 36: ?>
 37: <body>
 38: <?php displayLink(); ?>
 39: </body>

Click to view a working sample of this page here.

WordPress Tags: Display,Links,Link,Education,code,Google,Internet,text,Click,Development,adjustments,makeClickableLinks,eregi_replace,displayLink,clickable

Read Full Post | Make a Comment ( 1 so far )

Don’t Forget to Clean Your Code!

Posted on June 17, 2009. Filed under: Main, Microsoft, Tech Tips, Web Development | Tags: , , , , , |

I recently was asked to update a Web page with a rather long list of names, which were provided in a Word document.  I use a combination of Dreamweaver and Expression Web, because they both have good tools for stripping out problematic HTML from Word, but today they weren’t much help.

This particular document had a table (of sorts) built into it, which listed names and cities, but after a good ol’

copy and paste, I found that things didn’t quite line up.  Upon closer review, I found that the “table” was actually made up of tabs and spaces.  While this worked in Word, it made a horrible mess for the Web.  Just doing a copy and paste job created spaces (technically non-breaking spaces — “nbsp”) that seemed like empty space, but actually take up quite a lot.  In fact, these spaces made the page 322kb!  Most of the larger pages on the site were around 20-25kb, so I took another look at things.

In this case, I decided not to go with a table for the little bit of text that could fit in, instead going with the city name in parentheses after the person’s name.  After removing all the nbsp’s from the code, I was able to shrink the page to 32kb – a 90% reduction in page size!  That means the page will load in just over 1 second, instead of over 12 from before.

So, to recap:

  1. Copy and paste doesn’t work as expected with the web, so be prepared to clean up your code a bit.
  2. Check for spaces that don’t belong, particularly the “ ” – they take up more space than just hitting the spacebar does.
  3. Use a tool like Firebug for Firefox, or the built-in tools in several other browsers (IE8, Safari 4, Chrome) to test your page for load times and see how you can improve them.

Windows Live Tags: Code,Word,Dreamweaver,Expression,tools,HTML,spaces,text,reduction,size,Copy,tool,Firebug,Firefox,Safari,Chrome,nbsp

WordPress Tags: Code,Word,Dreamweaver,Expression,tools,HTML,spaces,text,reduction,size,Copy,tool,Firebug,Firefox,Safari,Chrome,nbsp

Read Full Post | Make a Comment ( None so far )

If you need to track your mileage for work, here’s an easy tool for you

Posted on February 20, 2009. Filed under: Main, Software, Tech Tips | Tags: , , , , |

 

Many small business owners and consultants spend time on the road in their personal vehicles traveling to clients and work sites.  We know those miles need to be tracked for tax purposes (money back from the IRS is a good thing), but it’s often a pain to do.  That’s where the TripBook comes into play.

(more…)

Read Full Post | Make a Comment ( None so far )

"Could not Open Install.Log File!" Problem Solved!!

Posted on February 3, 2009. Filed under: Main, Software, Tech support, Tech Tips | Tags: , , , , , |

I recently installed some backup software for testing and decided to remove the ones I wasn’t interested in anymore.  My hard drive has had some corruption issues, which means I’m losing programs, but don’t know it until I try to start them and something fails.  This, I think, is what happened with today’s problem.

(more…)

Read Full Post | Make a Comment ( 1 so far )

Are your programs up to date?

Posted on January 27, 2009. Filed under: Main, Software, Tech support, Tech Tips | Tags: , , , , |

I often find myself installing software for a specific purpose (testing, maintenance, etc.) and not using it regularly, which means it’s probably outdated when I need to use it again.  Sometimes it’s a game that is still being developed (like Frets on Fire, a free, great Guitar Hero style game for your PC) that gets updates pretty often.  When I go to use it after a while, I have to take the time to update it to the latest release before I can use it, which is kind of a pain.

Fortunately, there are a couple of programs out there that minimize the hassle of updating software.  While they don’t automatically update the programs that are installed on your machine, they make it easier for you to do it when you have some free time.  Let’s take a look at a couple of them.

(more…)

Read Full Post | Make a Comment ( None so far )

Foxit PDF Preview Handler

Posted on September 27, 2008. Filed under: Software, Tech Tips |

I love the preview feature built in to Windows Vista and Outlook 2007, but have been frustrated that the only way to view PDF files within Outlook preview is with Adobe Acrobat.  Since I use Foxit PDF Reader, which is faster and smaller, I haven’t been able to use the preview feature.  Until now, that is.

Thanks to Tim Heuer, you can now use Foxit PDF Reader with Outlook’s preview feature.  He’s written an add-on that allows Vista users who use Foxit to preview PDF files within the Outlook 2007 Reading Pane.

For those of us who are still (or also) using Windows XP with Outlook 2007, good news!  Tim’s now created an add-on just for us.  You can read about it and download it from Tim’s blog.


Related links:

Foxit PDF Preview Handler (Vista)

Foxit PDF Preview Handler (XP)

Download Foxit PDF Reader

icon_getreader

del.icio.us Tags: ,,,
Read Full Post | Make a Comment ( None so far )

Making Excel Charts Even Easier

Posted on August 31, 2008. Filed under: Main, Microsoft, Software, Tech Tips |

If you’re like me, you crunch numbers.  It may be sales, inventory, finances, or any number of things.  You probably use Microsoft Excel; maybe you even need a chart now and then but avoid it because it’s just a bit too crazy. 

If this describes you (even a little), check out the Chart Advisor from Office Labs.  These folks have been putting out some good Add-Ins that run within various Office programs.  This one evaluates your data, creates a chart, and automatically puts it in your spreadsheet.  I’ve tried it and am immensely impressed with it.

Here’s the official description:

Chart Advisor is a prototype that provides an alternate approach for creating charts in Excel 2007. This add-in uses an advanced rules engine to scan your data and, based on predefined rules, displays charts according to score. Top scoring charts are available for you to preview, tweak, and insert into your Excel worksheet.

 

Read Full Post | Make a Comment ( None so far )

  • August 2017
    S M T W T F S
    « Jun    
     12345
    6789101112
    13141516171819
    20212223242526
    2728293031  
  • Meta

  • Categories

  • delicious tags

  • Blog Stats

    • 10,514 visits

Liked it here?
Why not try sites on the blogroll...