Strip It

I had a very specific idea of how I wanted the homepage on my site laid out. I wanted either the entire latest post front-and-center in my content area, and below that I wanted to have 2 columns with excerpts from the two previous posts. I know there’s probably a way to do this with Movable Type, but the easier solution to me seemed to be writing a PHP page that grabbed the info I needed from my Movable Type database.

The only problem with that concept was that I couldn’t use the excerpt tag if I wasn’t building the page through movable type. Well, I knew I could shorten the post to a specified number of characters by using the LEFT string function in my SQL query.

LEFT(mt_entry.entry_text, 500)

The only problem this left (no pun intended) was that I didn’t want to see any images, pre tags, links, etc. in these "Recollections". What I needed was a way to remove all the html from these strings. I was really close to writing a regular expression to do this when I ran across a very useful PHP function: strip_tags. With strip_tags, all I had to was change:

<?php echo $row_Recollection1['entry_text'];?>


<?php echo strip_tags($row_Recollection1['entry_text']);?>

2 comments on “Strip It

Ryan says:

Totally off topic, but the validators at the bottom of your template show that this page is not valid XHTML or CSS. You need to close the img tags, son!

You are so getting blacklisted, Ryan! It’s fixed.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to the top!