Remove Widows and Orphans in Text Using PHP/Smarty

This script accepts a string and then places a non-breaking space between the last two words.

Passing the string to the script:
{include file=”widow.tpl” string_to_widow=$}

{assign var=’string_to_widow’ value=$string_to_widow}

$original_string = $this->get_template_vars(‘string_to_widow’);

$original_string = str_replace(‘$’,’dollar’, $original_string);
$original_string = str_replace(‘%’,’percent’, $original_string);
$original_string = str_replace(‘.’,’period’, $original_string);

$array_string = str_word_count($original_string, 1, ‘1,2,3,4,5,6,7,8,9,0’);

$array_count = count($array_string);

$widow_string = $array_string[$array_count-2] . ” ” . $array_string[$array_count-1];

foreach ($array_string as $k => $v) {
if ($k != $array_count-2 && $k != $array_count-1) {
$final_string = $final_string . $v . ” “;
else if ($k == $array_count – 1) {
$final_string = $final_string . $widow_string;

$final_string = str_replace(‘dollar’,’$’, $final_string);
$final_string = str_replace(‘percent’,’%’, $final_string);
$final_string = str_replace(‘period’,’.’, $final_string);




Search and Replace in Smarty

How to find and replace part of a string in Smarty:

{$string_variable|replace:”Old Word”,”New Word”}

Running IE6,7,8 on my Laptop

First, I’m going to install Windows Virtual PC:

Then I’m going to install ones of these pre-packaged images with IE6 included.




Slideshow and Photo Gallery

Javascript based: SmoothGallery

Flash based: SlideShowPro

Create Javascript “mailto:” Link

To create a “mailto:” link with Javascript that has less of a chance of being harvested by spammers:

“System.Web.Mvc.ViewMasterPage” Parser Error

I’m currently working on my first ASP.NET MVC app, code name Biscuit. I edited some Master Pages today and upon starting my app received the following parser error:

The type ‘System.Web.Mvc.ViewMasterPage’ is ambiguous: it could come from assembly ‘C:\Windows\assembly\GAC_MSIL\System.Web.Mvc\\System.Web.Mvc.dll’…

Turns out one of my new Master Pages had .cs and .designer.cs files attached.

As explained in this ASP.NET forum post, the namespace for my .designer.cs file has been changed to: System.Web.Mvc, which is why the site got confused.

The solution for it going forward:

The Holy Grail of CSS: Equal Height DIV Columns

Back in prehistoric web times, we used tables for our column layout needs. Now we know better and use CSS and DIVs instead. However, getting side-by-side DIVs to extend to equal height has proven to be quite the elusive task. Until I stumbled upon Ed Eliot’s brilliant, simple solution for equal height DIVs using CSS, I played all sorts of reindeer games.

Let’s explain. Say you have a 3-column layout, one DIV for each column. Each column has content of differing length. Left to their own devices DIVs will only expand as far as their content. This is not an issue unless you have a background of some sort or color assigned to each DIV, and you want all the columns to be of equal height.

Ed’s solution involves a few lines of CSS to each of your DIVs: the outer container, the left DIV, the center DIV, and the right DIV.


Lorem ipsum dolor sit amet
Lorem ipsum dolor
Lorem ipsum

And here is the CSS. The values for margin-bottom and padding-bottom are arbitrary:

    width: 350px;
    margin: 0 auto; 
    overflow: hidden; 

    float: left;
    width: 100px;
    background-color: green;
    color: #fff;
    margin-bottom: -1000px;
    padding-bottom: 1000px;

    float: left;
    width: 100px;
    background-color: red;
    margin-bottom: -1000px;
    padding-bottom: 1000px;

    float: left;
    width: 100px;
    background-color: yellow;
    margin-bottom: -1000px;
    padding-bottom: 1000px;

Here’s the finished example:

Lorem ipsum dolor sit ametLorem ipsum dolor sit amet
Lorem ipsum dolor
Lorem ipsum

Beanstalk: Version Control for a Solo Developer?

As a one-gal dev circus I am always looking for cool, new, and inexpensive (read: free) ways to create better apps more efficiently.

A workable version control and code repository app has eluded me for some time, and every day that passes without one is one day closer to my own personal apocalypse. At the Day Job we use SourceSafe (I know, I know!) but it’s a dinosaur and quite frankly, not very sexy.

CVS was rather alien for a Windows developer like me and Subversion looked like a contender until I tried to set it up all by my lonesome.

Now, there’s Beanstalk to the rescue! It’s essentially a hosted Subversion with an extremely user-friendly interface and more importantly, it’s free for up to 3 users, 1 repository and 100 MB of storage. That’s perfect for the solo developer who wants to be a good kid and version and back-up their code.

I just signed up and am excited to put on my Responsible Developer Hat. I will post more about my Beanstalk experience after I’ve had some time to play with it.

reCAPTCHA: A CAPTCHA for the Cool Kids

Looking for a free CAPTCHA? reCAPTCHA is a free CAPTCHA service offered by the smart folks at Carnegie Mellon. You can insert the code just about anywhere and they have plugins for WordPress and PHP to make it easy. There are also detailed instructions and examples for multiple languages and platforms.

I’ve used it on many ASP.NET sites already and it works like a champ.

© Copyright 2009-2010 Alpha Papa Hotel . Thanks for visiting!